Juha-Matti Santala
Community Builder. Dreamer. Adventurer.

45 stars, Christmas was almost saved - Advent of Code retrospective

Advent of Code 2021 is over and I not only got a major new personal record, I got very close to my first completion. Here's a retrospective of the things I learned and/or thought during the 25 days of Advent of Code.

My toolchain of choice for this year was Jupyter Notebook with Python and instead of writing daily blog posts on this blog, I kept writing lightweight blog-style commentary into the notebooks together with the solutions and shared them in GitHub: hamatti/adventofcode-2021. I'll migrate them to this website once I manage to decide what kind of sub-site I want to make for them.

I love the lore

Helping Santa and the elves to save Christmas. Bingo playing giant squid, glowing lanternfish, crabs in their tiny submarines and so on. Year after year I think Advent of Code is a masterpiece in puzzle lore.

And the lore is lovely in a way that it's non-intrusive when it comes to solving the puzzles. It just adds a little something that you can smile at when you start your daily puzzle solving routine and then forget until you solve it and advance in the story.

Python is a fantastic language

After last year of trying to learn a new language while solving these puzzles, this year I decided to pick a language I'm very comfortable with and that I enjoy.

And oh boy I've been enjoying working with Python this December. I spent quite a lot of time reading the standard library docs for itertools, functools, collections and re and all of them are excellent libraries.

For puzzles like these, I really like the flexibility and dynamic nature of Python. It makes it easier to quickly flesh out the code that takes an input and produces an output.

Occasionally (like in day 18), I abused the flexible type system by returning different things based on the situation. Probably not the best thing to do in real life but combined with the structural pattern matching that came with Python 3.10, it allowed me to craft a solution that I might not have otherwise done.

A good spec is worth its weight in gold

The creator of Advent of Code has improved his spec-writing skill immensly over the years and I thank for that. In 2021, the quality and understandability of the puzzle descriptions and the examples provided was top notch.

And it reminded me of how bad the real life software projects often are. It would be so nice to pick up a ticket from the backlog, have this level of descriptions and get working. But no. Often it's "X is broken" level of tickets that take at worst days to even understand what the problem actually is.

Sure, for artificial puzzles it's easier to define the "definition of done" but even if that's bit unclear, providing enough information in the ticket is something I think we as the industry need to become better at.

A key to these in my opinion is having a good set of examples that really help to make sure that you've understood the problem correctly.

Tree structures are hard to debug

My biggest struggle throughout the month was the multiple puzzles that called for a tree structure and recursion to solve. I'll admit, I'm not great with trees.

I learned about them in the university a decade ago and can reason with the theory part but implementing it in code is a different challenge. I did improve a lot in my ability to do that but there was one major thing I realized during this time:

My workflow is very debug-driven – and my current toolkit for debugging doesn't translate well to trees. So many times I had relatively simple bugs that I struggled to figure out because I couldn't debug like usual.

In non-recursive, non-tree solutions I can pretty much always say "I want to inspect the state at this given point" but when traversing trees with recursion, I can't and the amount of times functions are run even on rather smaller trees is so large that any print-debugging just fills the screen.

So many ways to solve and options to focus on

One thing I absolutely love about Advent of Code is that it offers a way to decide on your own what you want to focus on. Last year for me it was learning Rust. This year it was working on improving my writing. For some, it might be getting high scores on the leaderboard and for others, writing the most performative code they can.

For me, learning is always the key. I didn't have any hard rules for this year but I ended up solving all of them without any libraries outside the standard library (and my own utils library for reading inputs). But if I'd have decided one day to pick up a library because it would have been a good opportunity to learn it, I would have.

Learning with friends is awesome

Another aspect of Advent of Code that I like and have said on probably every post I make about it: community is great. So many developer communities are buzzing during the month of December which offers lots of peer support, opportunities to learn and someone to rant with when things are hard.

And part of that is sharing my own solutions with people and getting feedback and learning more based on them.

There's also a very active sub-reddit at r/adventofcode but I've never been a redditor so I've only gone there a few times to check the memes. People also share a lot in blogs and social media so searching for "Advent of Code" on those platforms or Google is a great a way to learn more material.

Puzzle solving skills != development skills

Solving puzzles like these can be frustrating. I've never used tree structures in my day-to-day work as a developer nor have I needed any math tricks to get through my work. Outside job interviews' bullshit technical trivia questions and puzzles, this kind of skillset is not most often needed.

So if you're like me and really struggle getting through some of these puzzles, don't worry. Some of the best developers I know are horrible at solving puzzles but awesome at building usable and accessible products that solve real-world problems and are delight to use.

Puzzle solving (just like for example Code Golfing) is a very specific sub-category of software development. Working on those puzzles can be rewarding and it can really help hone the basic skills. I can't remember when I've coded for 25 days straight before, working on the fundamentals but this month I did and learned a ton.

I got a bit addicted

One thing that happened midway through was that I got bit addicted on these and started solving the first Advent of Code from 2015 as well. In 3 days, I managed to get 44 stars and I'm planning to finish those last 6 one day too.

And I might do the other years as well, especially now that I've enjoyed the Jupyter Notebook + Python combo quite a lot this year. Would be cool to have a full collection of 350 stars together with full written commentary on each puzzle.

But it's also very likely that I don't want to see another puzzle for another year now that I'm through.

Day 19 was the hardest

Despite me saying in the beginning that the tree puzzles were one I struggled with most, day 19 was the hardest one for me. Not because the solution to it would be that hard to implement (contrary to those trees) but because I had hard time understanding the math related to it. 3D geometry is not something I've done since high school 15+ years ago so understanding how to solve it was such a challenge.

The other one I failed to do was the 24th, mostly because it was the Christmas Eve and it was much more important to spend the day with the family than coding. I got close enough on that day to know that I could have solved it with a bit more time.

So close

All in all, I'm very happy with this year's result. But also, getting so close to the 50 stars and not managing to complete it is slightly annoying the perfectionist in me. But given that my previous record from 2020 was 15 stars, 45 is a huge deal.

I also had some ideas for the community side that didn't get done this year that I'll keep in my notes for 2022 so there would be something new coming also next year.

Now it's time to wrap up 2021 and head over to the new year.

Syntax Error

Sign up for Syntax Error, a monthly newsletter that helps developers turn a stressful debugging situation into a joyful exploration.