Why you should try Advent of Code
Why AoC?
I’ve long wanted to write a blog promoting the merits of Advent of Code and - since it has just wrapped up its fifth year - there seems to be no better time like the present.
Advent of Code (or AoC as I’ll refer to it hereafter) is a solo effort by Eric Wastl. Commencing each year on December 1st, it presents an advent calendar-style series of daily programming challenges in the lead-up to Christmas. Whilst there may be no shortage of “coding challenge” sites out there, AoC is my personal favourite. Of its peers, I personally find the Project Euler problems to be too dry and maths heavy, while LeetCode and Code Wars can be too heavy on testing algorithm knowledge whilst also being prescriptive in the languages you can use to submit your solution. So why does AoC stand out?
The problem statements are creative
Take a look at AoC2019’s first problem. As a newcomer to AoC, you might be thinking “what’s all this nonsense about Santa and interplanetary travel and elf rockets? The actual question doesn’t start until five paragraphs in? What the?”. And yes, every question is like that. And yes, I love it.
I appreciate this opinion may not be shared by everyone, but beyond the novelty of the narrative framing structure for the questions, I think they test important skills in being able to parse a potentially-quite-complicated problem and reduce it down to its core. Real life problems are rarely so cut-and-dry in their appearance; they’re loaded with baggage, some of which will be critical to keep with you, and some of which won’t.
You can solve them how you want
Each AoC problem is framed in a way to require a simple answer, typically a number or a word. Unlike other sites, AoC is not interested in how you choose to solve the problem, merely that you manage to solve it correctly. I’m not ashamed to say I even solved 2019’s Day 17 Part 2 by hand, and I’ve done similar in a previous year’s problem.
It’s rare that you’ll need to possess advanced skills in any programming language in order to solve an AoC problem. If you’re comfortable with simple techniques such as array/list/dictionary manipulation you can go a long way. The challenge will often come in how you choose to employ these skills to solve a problem efficiently (we’ll get to that).
You’ll learn stuff
Because of this, AoC is a great opportunity to learn a new programming language. With a handful of problems you’ll likely be exposed to all the language fundamentals - types, data structures, I/O, loops, logic, and more. For the last few years I’ve been using AoC as an excuse to keep my Golang knowledge up, because I’d rarely get a chance to exercise it in a professional sense.
Beyond just programming fundamentals, AoC problems will often dabble in some comp-sci topics as well. When I first started doing AoC, I’d come from many years of doing Java Enterprise programming, and I hadn’t needed to even think about graph traversal algorithms in a good decade or more. Suddenly (and humblingly) I needed to remind myself of how to write a breadth first search. It’s usually rare that a problem is unsolvable unless you know a particular technique or algorithm in advance (though I think this year’s day 22 problem has stirred up some debate around that). But AoC is a great way to refresh some of that old knowledge that you might have put aside once university finished.
The dreaded part 2s
Each day’s problem is split into two parts. The first part (and the only part you’ll actually be presented with, until you successfully solve it) will usually be straightforward. The second part, not so much - they’ll often bolt an additional constraint or condition onto the existing problem that complicates things significantly. The best “part 2"s are the ones that test how well you managed to solve part 1. There’s nothing worse than realizing that a shortcut you took to solve part 1 is now going to ruin your chances of solving part 2 without a refactor or rewrite. Conversely, there is rarely a better “Hell yeah!” feeling than when you realize you can do a simple tweak to your existing awesome solution and solve a part 2 in a matter of moments.
Good “part 2” questions will often also massively increase the complexity or scope of the problem, meaning that your method for solving them is going to require more thought or optimisation in order to be computationally solvable in a reasonable time frame. For example, 2019’s Day 20 first asks you to find the shortest path through a maze where exits are interconnected by portals. Part 2 presents a scenario where the maze is infinitely recursive and the portals will take you to an inner/outer level of the maze.
In short, the “Part 2"s are a very uniquely-AoC sort of thing, with the benefit of being quite clever and putting a brow-furrowing spin on the problem.
The community is awesome
The AoC community, which is mostly found on Reddit, is one of the best out there. People put genuine effort into helping others overcome their coding roadblocks. Some will go the extra mile with problems and create some absolutely bonkers visualizations of the problem being solved, which is always impressive to see. This year in particular has been exceptional with how people have upped the ante.. but we’ll talk about that in the next post.
Wrapping up
This has already gotten so long that I’ll wrap it up here. In the next post, I’ll talk specifically about why 2019’s AoC was so impressive, as well as give my general thoughts on tackling it for another year.