First: this is pretty cool. I don’t remember the animations starting before the end of the competition.
Today’s puzzle would have wrecked me when I first started doing AoC puzzles, back in 2020. I must be learning something, as I managed it in relatively short time (less than two hours, all told), without having to run my code on the example.
I used the following tools, and I’m pretty sure that each, or some variant of each, is necessary.
- A beam can end up in an infinite loop. (I haven’t verified this, but I’m pretty sure it’s true.)
- To prevent this, we need a way to verify the beam isn’t repeating previous steps; i.e., a beam tracker. But it’s not enough to test if a beam passes through a point; we need to test whether it passes through a point in the same direction as before. If it passes through a point in a different direction, then it should keep moving.
- When you get to Part 2, don’t forget to clear the beam tracker before you start a beam on an edge. I forgot to do that, and ended up with a result roughly twice as large as the correct answer.
- Splitting leads to new beams; my maximum number of beams was 65. Since we are searching for energized tiles, BFS struck me as the perfect tool to find them. The criterion to prune branches is the record of energized tiles.
I’ll see if I can come up with a visualization of Part 2’s solution later. I did create a visualization for Day 14, but it wasn’t very helpful, and the forum rejected it as being too large an image, so I shrugged it off.