Since 2020, every year I solve the Advent of Code puzzles. Also, every year I write an experience report about my 25+ day journey in December. Read my thoughts about previous years here: 2020, 2021, 2022 and 2023.
Spoiler alert: If you still work or plan to work on the puzzles, stop reading now.
Puzzles
Between December 1 and December 25, a programming puzzle appears every day on the Advent of Code website. Each problem has two parts, the second part unlocks after you complete the first. To understand each day’s puzzle, go to the website and read the full description (for example Day 1: Historian Hysteria).
Setup
My setup and goal remain the same as in the previous years: I use Clojure and I try to write succinct and comprehensible programs.
I don’t have a specific library of helper functions for the Advent of Code, but I have a best-first search implementation that I find useful in many problems. This year — in particular in days 16, 18, and 20 — I expressed the solution using this function.
My Day 16, Day 22 and Day 23 solutions run for about a minute, but I didn’t have the energy to optimize them.
Highlights
The first difficulty arrived on Day 12. The puzzle asked for counting the straight edges of polygonal “gardens”. Initially I didn’t find a good approach for identifying a garden’s boundary. When I started to track the normal of each point that form the boundary, my solution started to make sense.
I solved Day 13 with pen and paper then I implemented the resulting formula in code.
Day 14 had a picture of a Christmas tree hidden in the solution, so I wrote:
(defn solve-part2 [input]
(first (🎄 input)))
Day 15 reminded me of Sokoban, one of the first games I played on a computer. I enjoyed this puzzle even if the second part of took me a few attempts to get it right. I experimented with using Clojure’s dynamic bindings to write code that solve both parts of the puzzle.
Debugging the assembly code in the second part of Day 17 went much better than in a similar problem in 2021. I worked on this problem together with a colleague which made it even more fun.
I couldn’t solve the second part of Day 21. The puzzle asked to find a shortest command sequence to control a robot pressing buttons on a numeric keypad using a series of directional keypads. I keep thinking about this problem, but so far I didn’t have the motivation to go back to it.
On Day 24 I didn’t write any code for the second part. The puzzle asked for finding four incorrectly wired logic gates of a full adder. Using Graphviz, I generated a diagram from the puzzle input and I looked for nodes which caused visible irregularities.
Summary
I could solve all but one problem during the 2024 Advent of Code: my best year so far.
You can read the code of my solutions on GitHub.
Acknowledgments
Thanks Eric Wastl for creating and running Advent of Code.