The Advent of Code is an annual programming challenge which has been running every December since 2015. Every morning (depending on your timezone) a new, two-part puzzle is released, and people all over the world race to collect the stars and save Christmas / help Santa / fix snow production or otherwise rescue the World from calamity.
The website and the puzzles are deliberately kept in a very low-key, mostly monochrome, text-only format for maximum accessibility. Yet the worlds it describes are varied, dramatic and occasionally vast. Therefore, visualising these problems in different ways is a popular, yet entirely optional extra activity.
Not all of the puzzles lend themselves to useful visualisation, so here I've picked out three from this 2023 calendar to turn into animations. Perhaps some of the behaviours shown here uncover surprises in the way these things actually change.
In this puzzle, molten lava has been collected from the production facility and needs to be transported to the factory with a minimum amount of heat loss. Wheeled crucibles can transport the lava across the city grid in a frighteningly high number of possible routes, each of which incurring a corresponding heat loss. The problem is to find the best route so that the lava is still as hot as possible when it arrives at the factory.
Part 1 (click for animation) | Part 2 (click for animation) |
There are certain restrictions on the movement of the crucibles, and these restrictions are different for parts 1 and 2, this is why the exploration front (the squares with yellow highlights) are different for each. Part 1 has (almost) vertical and horizontal fronts, whereas the dynamics of part 2 introduce diagonal fronts.
The exploration continues for some distance inside the main front, and "boils" around in a more complicated way for part 2. Also the final temperatures appear in a more "blocky" way in part 2, especially around the origin in the top-left corner.
How it was made: python and pillow to produce png frames and then combine to a webp.
In this puzzle, an elf is exploring a garden containing scattered rocks. The problem is to find out how many of these square plots the elf can visit after a given number of steps (each one going north, south, east or west, not diagonal).
In part 2, the garden becomes infinite, so the squares which can potentially be explored by the elf expand outwards in all directions, and the number of squares covered expands dramatically.
Part 2 (click for animation) |
The important point is to find the patterns in this exploration, and here I'm focussing exclusively on the exploration front to the west. With each step, the elf can additionally explore one more square in any direction from each of the previously visited squares (those marked in light blue), as long as it's not occupied by a rock (marked here as grey squares).
I'm scrolling the view here to keep track of the furthest point to the west which can be visited by the elf, but obviously a very similar picture would emerge by tracking the other extremities too.
The surprise for me here was how diagonal and straight the wavefront actually was, I thought it would be much more strongly affected by the rocks and deformed to be non-linear.
The looping animation here also emphasises the regularity of the patterns, as the garden (and its rocks) repeat infinitely in all directions.
How it was made: same as day 17, with python and pillow to produce png frames and then combine to a webp.
This puzzle has another maze to navigate, but with a twist — instead of trying to find the shortest path from the entrance to the exit, this time our protagonist wishes to take a long walk through the forest and this needs to be the longest walk possible in order to enjoy it to its fullest ;)
In part 1 we're not allowed to walk uphill because the slopes are steep and icy, so many of the possible paths are not possible, hence the longest path from top to bottom only covers a fraction of the forest. In part 2 we realise that going uphill is also possible, so the search space increases substantially.
Part 1 (click for animation) | Part 2 (click for animation) |
In these animations the forest paths are marked in green, and the optimum route is highlighted in yellow. For part 1 uphill slopes are forbidden, so the network is quite limited, but for part 2 it can take advantage of the uphill slopes as well to produce a much longer route to the exit (over three times as long).
How it was made: python to produce pov files, povray to produce png frames, and then python and pillow to combine to a webp. Calculating the heights of each part of the forest is not completely trivial though, because the heights are only required for the 3d visualisation, not for the solving of the puzzle itself!
Not all of the days lend themselves to animations like this, but maybe there are some from earlier calendars which could also be visualised in similar ways?
If you have any ideas, just let me know.