Notable problems from Advent of Code 2021
Tags: adventofcode, python
Published: 2021-12-26 03:26:21

[Advent of Code](https://adventofcode.com/) (AoC) is a yearly coding challenge in the form of an [Advent calendar](https://en.wikipedia.org/wiki/Advent_calendar). Every day from Dec 1 to 25, a small programming puzzle is released and [hundreds of thousands](https://adventofcode.com/2021/stats) of people attempt to solve the problems.

As this year’s Advent of Code comes to a close, I wanted to reflect on my AoC journey thus far.

![Advent of Code Calendar](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u6brjm8jfwcpvpjkelo5.png) 

---

These are some of the notable problems from this year.


## (Top favourite) [Day 16: Packet Decoder](https://adventofcode.com/2021/day/16)

This was by far my favourite problem. Although [my solution](https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2016/Day16_next.py) was not the shortest, I used object-oriented principles/features like inheritance and abstract classes and was very pleased with how my abstractions turned out. I’ve heard that the [2019 Intcode](https://esolangs.org/wiki/Intcode) problems were similar to this and I’m excited to work on them next!


## (Most enlightening) [Day 6: Lanternfish](https://adventofcode.com/2021/day/6)

This problem involved simulating a bunch of fish that would spawn new fish every 7 days. Like many others, [my first instinct](https://github.com/xlzior/advent-of-code/blob/main/2021/Day%206/Day6_brute.py) was to treat each Lanternfish as an individual entity (e.g. as a Python object) and iterate through an array of individual fish to spawn new fish. This worked fine for part 1 but not for part 2, which involved simulating more than 10<sup>12</sup> fish.

This was clearly not feasible and I was forced to try a [new approach](https://github.com/xlzior/advent-of-code/blob/main/2021/Day%206/Day6.py). I realised that each _individual_ fish was not important and that I could group the fish based on the number of days until they next spawn a new fish. Hence, the only relevant piece of information was how many fish there were in each group. I was glad that I had arrived at this realisation all on my own, which made for a far more memorable learning experience compared to if someone had told me the trick directly.

This concept (stop trying to deal with things as individuals, group them and keep track of only the relevant aggregated information) seemed to be a recurring theme and it came in useful for _**[Day 14: Extended Polymerisation](https://adventofcode.com/2021/day/14)** ([my solution](https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2014/Day14-3.py))_ and _**[Day 21: Dirac Dice](https://adventofcode.com/2021/day/21)** ([my solution](https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2021/Day21-2.py))_. To this day, I remember this strategy as the “Lanternfish optimisation”.

Later, I discussed my solution with two other friends who were also doing AoC and we realised that we had each come up with a different solution to the problem. We had a blast ~~arguing about fish~~ explaining our solutions to each other and we learned a lot from the discussion.


## (Most interesting) [Day 8: Seven Segment Search](https://adventofcode.com/2021/day/8)

This problem involved spotting patterns in the given problem statement and devising an algorithm that could eliminate possibilities, finally narrowing down to the last one. This was not particularly difficult, but there were many different ways to approach the problem. Some methods were more complicated and painful to code than others, while others were simpler and more elegant. I was not particularly pleased with my [first solution](https://github.com/xlzior/advent-of-code/blob/main/2021/Day%208/Day8-2.py), so I picked a cool algorithm on Reddit and [re-implemented it from scratch](https://github.com/xlzior/advent-of-code/blob/main/2021/Day%208/Day8_redo.py).

My main takeaway from this day was to identify the best/simplest algorithm on paper first, before starting to code. Perhaps if I had taken more time to look for the simplest pattern, I would have been able to come up with a simpler and more elegant solution on my own.


## (Most interesting) [Day 23: Amphipod](https://adventofcode.com/2021/day/23)

One challenge I had solving this problem was figuring out how to represent the problem in terms of code. I eventually treated it as a standard [shortest path graph problem](https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2023/Day23-2.py) to be solved using Dijkstra’s. What was unique to this problem was the way of generating neighbours, which was highly visual and involved generating possible next states given a current state.


## (Most challenging) [Day 19: Beacon Scanner](https://adventofcode.com/2021/day/19)

I did not particularly enjoy this one, but I’m glad I ploughed through and [finished it](https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2019/Day19-1.py). I did learn a lot from having to wrestle with the complexity of the problem. There are still optimisations I could make to my solution, but I’m in no rush to relive this day…


## (Most satisfying) [Day 13: Transparent Origami](https://adventofcode.com/2021/day/13)

This problem involved simulating folding a piece of paper with dots on it and printing the final output. This was not computationally difficult, but it made the list because the answer was extremely satisfying, in a visual way. It felt incredible to run [my program](https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2013/Day13.py) on the puzzle input and have it print out the letters very clearly in the terminal.

![Day 13: Transparent Origami Solution](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yvz613mnpll7nnrqozg9.png)