Advent of Code 2020

, .

This year I participated in Advent of Code for the first time. (Thanks a lot to my colleague Gabriel Birke for the suggestion!) I wrote a README.md file for each day’s puzzle – effectively one blog post per day – but I thought I’d write some summarizing thoughts here as well. You can find those READMEs along with my solutions at lucas­werkmeister/advent-of-code-2020.

Overall, I really enjoyed the experience, and I’m glad I did it. Some of the puzzles were a bit tedious, but most were fun and enjoyable. And while a handful of my solutions are inefficient or brute force, most of the time I managed to a reasonably efficient way to solve the puzzle.

I solved the puzzles in a variety of programming languages, depending on what I thought would be a good fit, or what I wanted to gain some experience with, or just whatever I felt like at the time. The GitHub breakdown shows that the repository is 82% Rust, but that’s in part because the Rust solutions tend to be longer (due to having more error handling, tests etc.); here’s the breakdown by day / puzzle:

Rust
12 of my solutions were Rust programs. I used Rust more frequently for the later puzzles; it was especially my choice of language for anything that needed performance or more complicated algorithms. I haven’t had that much experience with Rust yet, and I enjoyed getting to know it better; I feel like I’m starting to understand ownership and borrowing now.
Bash
7 of my solutions were shell scripts. I like shell scripts: they let you quickly iterate on a solution, trying things out on the command line before writing them into the script. Shell scripts can also combine different tools; for instance, for one solution (day 7), I used a fairly obscure GNU coreutils command, tsort, to perform a topological sort of the input. (1 more solution, day 15, started out as a shell script but was then rewritten in JavaScript.)
AWK
3 of my solutions were AWK scripts (some specific to GNU AWK, some should work with any POSIX-compliant AWK as far as I’m aware, though I only used GNU AWK), plus 1 more if you count day 10, which is a shell script but mostly uses AWK. I like AWK as well – the pattern of running commands for each input line, and then summarizing them in an END or ENDFILE action, worked pretty well for some puzzles.
sed
1 of my solutions was a sed program, though some of my other shell scripts used sed as well, of course. I did this one mainly to prove that it could be done, and that I could use more of sed than just the s command – this was my first time using the “hold space” in a sed program I wrote from scratch, I think.
R
1 of my solutions was an R program, since I thought its numerical capacities would be a good fit for day 12. It was nice enough, and I also happened to uncover a FastR bug.
JavaScript
1 of my solutions was written in JavaScript. Initially I wrote the day 15 solution in Bash, but part 2 was pretty much the same puzzle as part 1 except with a much higher limit, so that my Bash solution would not be fast enough to finish in any reasonable amount of time. JavaScript was the language where I thought it would be fairly straightforward to rewrite/translate my solution line-by-line – I trusted V8’s engine to optimize the code enough, and while it still took a while, it was good enough for me.

I’ll probably do Advent of Code next year again in some form. Maybe then I’ll use Rust every day – that would let me use cargo-aoc, which looked useful but didn’t really fit with this year’s repository layout of having one top-level dayXY directory per day.