"Part 2 seems hella cool. Would love to see this visualized."
That's what I wrote late at night on November 13, after finishing part 1 of Advent of Code 2019 day 20, and reading part 2.
This entire series contains major spoilers for Advent of Code 2019 day 20.
Part 1 is a two-dimensional rectangular maze with a hole in the middle, and several portals that each connect a point on the inside edge with a point on the outside edge. Part 2 reveals that this maze is recursive, and each portal on an inside edge connects with a point on the outside edge of the next level of the maze.
I formed a picture in my head of an inverted pyramid, with each inner level positioned below and a little bit smaller than the previous level. After solving the puzzle, I got some ideas about what a visualization of the search for the shortest path could look like. I've wished for a couple years that I could put together visualizations like the ones I've seen in the AoC subreddit, and I have a strong enough feeling about this puzzle that I think this is where I should start. A recent 3Blue1Brown video gave me the confidence that Manim would be the right tool, for me, for this first job.
Here's what I think I'll need to do to make it happen:
- Install Manim. Conda wanted to downgrade NetworkX in my base environment, so I'm creating a separate environment for Manim. My solution for this puzzle didn't rely on anything beyond the Python standard library, although Manim's dependencies resulted in somewhere close to 200 packages being installed!
- Enhance my solution to track the full path for each candidate. I'm pretty sure the number of branches to consider is small enough that I could assign each new branch a unique integer id and store the branch's full path at that index of a list.
- Enhance my solution to store the line segments for each path between portals within a level. While I'm using breadth-first search to identify the distance to any reachable portal, I'll also need to track the full path. Then in each path I'll need to combine adjacent steps in the same direction into a single segment.
- Create a static 3D image of my solution path for the larger example.
- Animate a new branch — adding to an existing path.
- Animate multiple branches. I imagine only the branch currently in focus will be fully illuminated. Perhaps the branch previously in focus will fade down to some minimum level.
- Tweak the entire visualization to give a sense of the space, movement, search, etc.
Top comments (0)