Reflecting on Advent of Code 2020 Challenge

By Nulltek

I found out about the advent of code annual challenge from some workmates who were raving about how much fun they were having solving these daily tasks. Initially I wasn’t particularly interested in completing it myself since my spare-time was already saturated with projects, however my competitive alter-ego had other plans. So… 12 days behind schedule I started tackling the daily coding challenges.

As to be expected the first few days of tasks were very easy for someone with a computer science background. After work I was easily completing 3 or so per-day. However some of the later tasks were deceivingly complicated, particularly the aptly numbered day-13. This task involved solving simultaneous congruences, a mathematical conundrum I had not previously encountered. I think it was a bit harsh to not mention the type of problem in the project brief, and a lot of the developers tackling this were probably blind-sided by this problem that is only realistically solvable using the ‘Chinese remainder theorem’. This particular day did dampen my enthusiasm for the challenge. Shortly after I departed for a road-trip, so day 15 was as far as my 2020 AoC attempt would go after 8 days of intense problem-solving.

I took away a lot of good skills from this exercise though. Particularly planning my code to be as light-weight and generic as possible. This is because the AoC tasks came in two parts: The first which sets the scene and gives you a basic problem to solve, and then part two which complicates the issue on the same data set. If you aren’t careful with your design for the first part, the second part can end up requiring you to rethink and refactor most of the code you’ve already written. This results in the duality of planning-ahead for the inevitable task-change balanced with not wasting time and over-complicating your codebase by trying to predict future problems.

I also gained more familiarity with a lot of python tools that I previously wasn’t calling upon that often.

  • Sets – Really helpful collections that’ll efficiently remove duplicates. Enjoys the same hash-able efficiencies of python dictionaries.
  • Enums – Something I use a lot in other languages, but haven’t used too much in python. A handy way to make difficult to read code intuitive with OOP representations.
  • Dataclasses – While I use these beautiful decorators introduced in 3.7 all the time, I had never appreciated how much this speeds up development. The intelligible generated __repr__ and default constructors really remove a lot of the boilerplate involved with creating simple objects.
  • Pathlib read_text / write_text – Object oriented paths is such a breath of fresh air, and having the ability to do 1 line file IO is very handy in some situations, again reducing a lot of the boilerplate for parsing small data-sets.

In the end I don’t regret attempting the challenge, and I’ll try it again in 2021. I will start a little earlier (1-Dec) though to give myself a better chance of keeping up with the daily releases.