Advent of Code 2021 (Days 6-10)

Source code

This is a continuation of my Advent of Code journey. Part #1 with days 1-5 can be found here, days after - 11-15, 16-20.

Day 06


The most painful of the puzzles so far. Parsing and data structures were all primitive; the thing I’ve hit a wall with was the overall pattern of the fish multiplication progression. I spent several hours(!) trying to grasp the principle behind, even taking hints from fellow “adventurers” from #lobsters-advent IRC channel.

Resorted to skimming through some solutions just to see some matrices multiplication and it was extremely frustrating to not understand what they have to do with fish swarm :)

After couple of valuable pointers finally was able to look at the input data and unfolding sequence differently - the function to process that data ended up dead simple, especially since I didn’t use matrices.

A quote was born that day: “Am I having infamous post-covid cognitive impairment or was I born that way?”

Day 07

The Treachery of Whales

Self-esteem still at 0K since yesterday; number sequences this time do not have a pattern but some averages calculation is required. Since I cannot remember some (or most) formulas by heard for the life of me resorted to googling without much remorse; luckily case from puzzle #1 is somewhat widespread so implementing was not an issue at all.

Part 2 clearly involved some different average type, I guessed “rough mean” and it turned out to be fine*. Fuel consumption calculation is basic arithmetic progression sum, that much was obvious at least.

Now the tricky part from #2 puzzle/solution is that the correct distance calc is distance * (distance + 1) / 2 but mean average goes for the distance^2 / 2 which is close enough to yield the correct answer in most cases. “Bruteforce” straightforward method apparently is somewhat viable here too, especially since I can split it into separate threads, so I implemented it as a validation method as well (just single-threaded though since it was more than enough for the input data).

Day 08

Seven Segment Search

Fairly easy tasks compared to previous days; first part was laughable easy but I knew 2nd one won’t accept any part of my dumb solution (which still worked fine so doesn’t really matter). Now second puzzle for me was all about solving one example on paper, then write down the process and implement it as a proper algorithm. Didn’t require that much of brain power but still was fun.

For whatever reason I started to rigorously keep all the input strings in my data structures to iterate through; midway I realized that knowing them doesn’t add anything and I can use bitmasks. That helped me quite a lot with comparing digit segments for intersections.

“Proper” part 2 implementation easily covered the first part solution as well. So far there was a number of cases where unifying both puzzle questions was a tricky part by itself, day 8 was soothing and straightforward here.

Day 09

Smoke Basin

Summing up todays puzzle: “Complicated task, simple solution”. Part 1 was as straightforward as it gets; part 2 listed some fairly complicated introductory clauses, but drawing the test map on a piece of paper showed some interesting things leading to an easy solution.

Day 10

Syntax Scoring

At first glance task looked quite intimidating; after thoughtful reading it turned out to be a simple case of “use stack structure”. Second part contained somewhat strange method of calculating the final result, felt like it was made more complex just to compensate the overall simplicity of the puzzle itself. I was able to reuse my quicksort implementation there though so it ended up being a happy occasion :)

Overall impression: “Plain but fun”.

Continue - days 11-15