Advent of Code 2021

2022-06-18

My experience of it.

Tags: programming


I got bitten quite badly by the Advent of Code 2021 (AoC 2021) bug, and ended up solving all the problems in Common Lisp. Here's a short, long-delayed review.

In case you don't know, Advent of Code is a programming competition where a new problem is released every day in the lead-up to Christmas, just like an advent calendar. The competitors are ranked according to how quickly they submit their solutions. I wasn't competing, and only finished the problems in late January.

Here are my linecounts for each of the 25 days.

Line counts by day. They range from about 10 lines to about 250 lines.

Generally, the later problems took more lines of code, because they were more difficult, but this wasn't universally true. I massively over-engineered some of the later problems, and went outside the scope of others. Day 24 includes the specification of a simple processing unit, for example, which I went ahead and implemented (unnecessarily). I also went completely overboard with day 17, which tasks you with calculating the trajectory of a projectile, and wrote a toy equation solver. Also bloating the line count is the fact that I usually copied helper functions between files rather than packaging them up for re-use.

Common Lisp was pleasant to use. It doesn't come with as many batteries as Python, but even Python users who are taking the competition seriously (like this person) will want to have their own data structures and algorithms library to-hand. It shouldn't be too much of a burden on top of that to implement simple functions like (read-lines file) and (split-string string). Speaking of that person, who happens to be the winner of AoC 2021, their post confirmed some of my ideas about what it would take to be competitive with the rest of the internet: lots of practice, a personal library that you know like the back of your hand, and automation software to download the problems at midnight and submit the solutions.

The only day I really struggled with was #19, which required knowledge about 3d rotations that I just didn't have. I ended up asking the sages of reddit for assistance. Oh, and I had a nasty bug on day 18, which was not triggered by the sample input. To debug it, I ended up taking someone else's solution, printing the data structure at each step of their code, and comparing the output to mine, which made it obvious what the bug was. Those were a rough 2 days.

I didn't need graphviz to solve day 12, but it was cool to be able to visualise the cave (see below). Data formats in general are cool and powerful! If you know PPM, for example, which is a simple ASCII storage format for images, then it's easy to visualise the output of a toy ray tracer in any language, because you just have to save a list of numbers to a file. With graphviz, you can easily visualise graphs in any language by writing a 5-line function that saves your graph data structure to a file in a very simple format.

Graph of the cave from day 12, it's just circles and lines connecting them.

I don't plan to participate next year, but it's a nice thing to do if you want to get your hands dirty with a programming language. After the competition, I felt like I could blast out code in Common Lisp fairly fluently (though still not as fluently as Python). I'm pretty sure I went through a similar process with Python, back in the day, when I was solving programming challenges to prepare for interviews.

Anyway, my solutions are here, if anyone wants to take a peek.


I'd be happy to hear from you at galligankevinp@gmail.com.