Advent of Code 2021 (Days 16-20)

Source code

This is a continuation of my Advent of Code journey: days 1-5, days 6-10, days 11-15

Day 16

Packet Decoder

Easy on brain task for a change of pace; all I had to do is jut parse some data basically. It was easier to process raw string data, so I just put together couple of universal functions like “hex string” -> binary string" and after that it was all straightforward.

This puzzle was amusing in regard of implementation - one of these tasks where you don’t have anything properly working till you finish all the small pieces, but after that it suddenly 100% and you’re done. Really enjoyed it, tricky parsing feels like real world puzzle - carefully putting together pieces one after another.

Day 17

Trick Shot

Single most disgusting puzzle solution I’ve wrote so far. Data is just 4 numbers both in test and “real” inputs, and being completely spent after work week I just hardcoded inputs . Next was a bruteforce solution; or should I say THE bruteforce solution :D Several guessed border numbers took me down to little more than 1 biilon tries producing right answers for both parts of the puzzle.

Thanks to -O2 compiler optimizations it runs under 1.5 seconds though.

Day 18


One of the hardest tasks so far. The obvious tree structure works really bad (or doesn’t at all) for the puzzle, and figuring out how to process data without losing own sanity was hard. As usual - seeing the “right” type of encapsulation structure is about 50% of the whole task.

Implemented a big chunk of parsing/processing code just to throw it all away later, the struggle was real and I even got a hint from folks from #lobsters-advent IRC channel.

Day 19

Beacon Scanner

The hardest puzzle that I failed for now. “I fought. I lost. Now I rest”.

At least it looks to me there is little to do with discrete math or algorightms and main problems are 3D-geometry and linear algebra here.

Spent whole Sunday with it, managed to make an overlaps detecting algorithm. Spent a ton of time implementing 24-way coordinates “rotation” for every point and wasn’t even sure how to utilize that after all :( Working with overlaps as distance unions was fruitless as well.

Late at night decided I had enough and that I will try to get back to this stuff some time later; shame I won’t have all 50 stars by the end of advent but guess that was my ceiling for speedy solutions :)

Update on day #25

Took me 50 gray hairs and 8 hours but I fought through this puzzle - was quite complicated for me, ended up with ton of nested loops but execution time stayed low thanks to clang/gcc :)

Day 20

Trench Map

Especially after day 19 this puzzle was “lightweight” and fun; felt like working with “real” image format. The tricky part of the puzzle was, obviously, the picture being infinite, but I managed to figure out how to process that data without just basic 2D arrays without even <math.h>

Continue - days 21-25 (end)