Advent of Code
Advent of Code 2022 began today. In case you’re not familiar, Advent is an annual coding challenge comprising 25 puzzles, released one per day beginning on December 1st. Participants don’t actually submit code, although they often share it online. Rather, they submit answers to simple questions that prove they’ve run code that solved the problem. Because each participant is given their own input to process, you can’t just copy someone else’s answer. (You could copy someone’s code and run it on your own input, but where’s the fun in that?) Even though you’re solving a specific puzzle, you really have to tackle the more general problem in order to find your specific solution.
What I love about Advent is that it’s a good microcosm of real-world software development, which is something other coding challenges struggle (and generally fail) to model. Aside from the lack of teammates and end users, completing Advent in real time (one challenge per day) takes you on a journey not dissimilar from most professional coding.
The first puzzle is logically easiest, yet in some ways also the hardest. You have to decide what programming language you’ll use, how to lay out your repository, whether to publish your solutions online, and so on. It really feels like you’re at the start of something. The first day also gets you comfortable with the structure of the puzzles, each of which has two parts: You have to complete the first part to unlock the second part, which asks you a new question about the same input. For example, if Part 1 wants you to sum a list of numbers, Part 2 might ask for the maximum of those numbers. So, right away, you’re almost forced to factor your code into three pieces: code that’s useful in both Part 1 and Part 2 (such as an input parser, or hard-coded input values if you’re a killjoy), code that’s useful only in Part 1, and code that’s useful only in Part 2. What an ingenious way to create engineering tasks from simple riddles!
After the first day, the puzzles get gradually harder, often building on earlier puzzles in interesting ways. Again, you’re forced to either refactor or copy/paste code so that you can reuse the logic from earlier solutions in new ones. Sometimes you realize that the data model you used for one puzzle isn’t right for another, even when the two puzzles are semantically similar. The multiple perspectives you gain on the problem space (artificial though it may be) force you to think deeply about it, and give you the incredibly satisfying feeling of understanding it.
Somewhere around December 20th, the difficulty skyrockets. Puzzles go from something you can do before or after work, to something that takes all day, or even multiple days. (Some years, I finish these on time; and some years, I don’t.) Somehow, in three short weeks, you’ve gone from the ease and excitement of a greenfield project to the tension and stress of being up against a deadline. Not the simple deadline of a traditional coding challenge, but a deadline for something you’re invested in. Something you take pride in, and want to show off to other people. You may not have “users,” but you do have peers, and you care what they think. Not even hackathons inspire the sense of urgency that late-stage Advent does. This may sound terrible, but no more so than the climax of a great story, when the hero faces the most powerful villain, and we truly doesn’t know whether the hero will win or lose. It’s an exciting moment.
One other thing that Advent does well is to walk you through sample input for each puzzle, and give you the answer for that sample. This gives you something to test your own code against, which is invaluable for debugging. There’s a lesson to be learned here for actual engineering: If you’re building something to work in the big messy nasty real world, make sure you can also run it on something small and clean and well understood. It not only makes debugging easier, but is often critical to making debugging possible at all.
Kudos to Eric Wastl, the creator of Advent of Code. If you’re participating this year, feel free to share observations and code links here. And if you’ve never tried it before, but you love a good coding challenge, you’re in for a treat. This really is one of the best.