Abstracting Rust code | Advent of Code 2022 Day 22

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

I've been rolling my own parsers, but today was a good day to use nom for the directions. I spent a bunch of time with the documentation trying to figure out how to express what I wanted. All of the generic arguments make the compiler's error messages hard to understand, so this wasn't just a case of "do what the compiler tells you to do". I parsed the map/board by hand (two nested for loops makes it trivial to parse and get row/column numbers).

let (board_str, moves) =
for (row, line) in board_str.lines().enumerate() {
for (col, ch) in line.chars().enumerate() {
// Do something with `ch`
}
}
// Parse `moves` with nom

With part 2, my brain is struggling with visualizing how to fold the 2-D map into a 3-D cube in order to figure out how the wrapping works. So I made a paper model to mimic the example input, labeling all of the faces and edges. Then I looked more carefully at the full input to confirm the dimensions of a face, only to realize that the way the cube is folded is completely different. I'm going to have to make another paper model. I'm not sure if my solution is going to work on both the example and the full input because the general shape is different. That's just cruel.

I have tediously written each of the wrap-around cases, but my part 2 answer is not accepted (and I didn't try to implement it for the example arrangement). I'll have to come back to this one later (and wait to watch your part 2).

markday
Автор

Part 2 would be good for a Bevy visualization ;)

epiicSpooky