2023 Day 16: The Floor Will Be Lava

First: this is pretty cool. I don’t remember the animations starting before the end of the competition.

AoC2023_day15

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.

Visualization of part 1! you may want to load it in a separate table and zoom in a bit, but it gets the point across. Pretty long! about 30 seconds.

all_frames_optimized_quicker

While I could create a visualization of the correct solution to Part 2, I’m not sure it would be any more helpful.

1 Like

Perhaps an animation, with one frame per entry point, showing the final state each time, could be cool.
I guess it will look like experiments with a Faraday cage, or a plasma globe.

I really like this puzzle. :slight_smile:

Probably also one of the puzzles where I learn most, because for part 1, I decided to implement beams as tasks updating a protected grid object (where each cell caches from which direction it was already visited).

Now on to part 2…

2 Likes

That’s pretty cool! :clap: :+1:

Back in 2020 I used Advent of Code to learn about Ada, and if I recall correctly, that was the year of Intcode, where odd-numbered puzzles required you to build an intcode virtual machine, adding new features with each day. At one point the machine went parallel, and like you, I decided to use task, though I don’t think I went the route of protected objects.

These days I’m a little lazier :grin: and use features only when needed, or at least convenient. I have asked myself on occasion if I should try a parallel loop or two, but I haven’t felt the need yet.