Advent of Code

Programming

Somehow I heard about Advent of Code and was intrigued by the idea. I rarely had the opportunity to solve this type of problems while working at my job or on any side projects, and when they did come up I did not always have the time to solve them to my liking. That is, getting to think about the best level of abstraction for the problem, implementing a solution that was not just functional but satisfying, or adding detailed tests. Or sometimes knowingly choosing a non-optimal, over-engineered solution because it seemed fun to implement. It decided that I would treat Advent of Code more like a playground than homework and try to have fun with it. I knew the problems would increase in difficulty until the time for me to solve them would become prohibitive, so I just took the challenges day by day and decided I would resign as soon as I hit a day where I could not finish both parts.

My desire to think about writing reusable functions even for the first part of each day’s problem became an interesting facet. I could see many different opportunities to introduce a new abstraction or more general function that seemed applicable to a wider class of problems. For some of the days, the second part of the problem benefitted greatly or even became trivial if I identified the correct opportunities while solving the first part. In other days, the problem would change differently than I imagined and my attempts to write code for future, unknown tasks would be clunky or even useless. Of course, this is a very familiar experience while writing code profesionally as the scope or requirements change. I found the exercise of trying to forecast future changes a fun game on top of just arriving at the solution.

In general, I had a lot of fun solving these problems. There were some recurring tools that I rarely used in my regular programming. As one example, I finally developed a deep enough understanding of regex that I could write my own regular expressions from scratch and understand patterns that previously just read like hieroglyphics. I also got to implement Djikstra’s algorithm for the first time. I was theoretically familiar enough with the algorithm to correctly identify the problem that required it, but I could not recall implementing it myself previously. Watching it solve a problem that would have otherwise been very challenging was certainly satisfying. By far, my favorite question was part 2 of Day 14, where I had to identify when a group of robots evolving on a grid assumed the form of a Christmas tree. The end condition was seemingly extremely underspecified, so the challenge of thinking about the abstract properties associated with a generic Christmas tree and then translating this to code was a fun exercise. And rendering the simulation for a few frames leading up to the frame suggested by my Christmas tree detection algorithm was magical as I saw all of the robots nicely fall into a beautiful tree.

Default A beautiful reward on iteration 6532 of the dynamics.

I ended up making it through day 17. The time demands were gradually growing, and acquiring the stars had started to come at the expense of workouts or sleep. I remember on the evening of day 17 heading out to a bonfire with friends knowing that I would not return with time to solve the second part. There was a sense of sadness, both in failing the challenge and ending what had become a fun challenge each evening after work, but also a sense of relief knowing that I could get my free time back. I also would soon have family in town, so it was inevitable that I would need to wind down my endeavor.

I really appreciated the careful thought that went into designing the problems, and most of them were fun to solve. I suspect this will become a new annual tradition for me if I can make time in my schedule.