Day 16: The Floor Will Be Lava

AdventuRust - AoC 2023

This is Day 16 of Advent of Code 2023! If you would like to solve the problems before looking at the solution, you can find them here.

In part 1 of Day 16, we have a ray of light entering a matrix of mirrors (as we often do). The light can be reflected, allowed to pass through as-is, or split into two - all depending on the relative positioning of the ray and the mirror. We need to figure out how many squares the ray of light (or its children after splitting) passes through before exiting the matrix. I took some time to parse the matrix into HashMap that stored all the positions that the light could enter into a square and where it goes after that square. The values for this HashMap had to be vectors in order to allow for light splitting. What follows is basically an implementation of BFS where we add all unvisited squares that are newly entered into a vector as well as the squares that have already been visited - the length of the latter is the answer for part 1. Click here to jump to the part 2 discussion.

For part 2 of Day 16, we do the same things as part 1 but go through all possible entry points instead of only the top left corner and find the maximum number of squares that can be visited. Again, I used rayon to fasten up the processing but not much else to see here. This brings us, sadly, to the end of my efforts for this year's Advent of Code. I set out, never having used Rust, to attempt a week of AoC and I did more than two weeks, making it to the ~12% that made it to Day 16 this year. I'm pretty happy with how it went, maybe next year I'll try to go further. Until then, stay rusty(?) Ciao.

That's all folks! If you made it this far, enjoy some AI art generated by u/encse using the prompt for this puzzle.