The Journal

Advent of Code

This is the first year I seriously committed to solving the Advent of Code. I don't care for the whole Christmas theme but I loved solving the enigmas.

February Update

At last! I have completed all the challenges of the 2024 Advent of Code. Today I was ready to give up and to shred my computer to pieces due to frustration and rage. I have to admit that I was stuck on 2 challenges: day 16 part 2 and day 21 part 2. Last night I completed day 16 and today I completed day 21. I'm not proud to admit that I got the last one by looking to some suggestions in Reddit that got me on the right track. I came very close to the solution a couple of times days before but I couldn't get rid of the code I wrote for the first part which was elegant but very inefficient. When it finally dawned on me what I'd been missing to complete the challenge I couldn't get rid of the old code fast enough.

The original article

So far I solved all 25 first parts and 21 second parts and that was surprising to me because I was convinced that I could solve all those enigmas without any help but I found myself throwing away half of my holidays helplessly trying to understand how to unwrap some enigmas.

Oftentimes the first parts are fairly easy to solve, usually you take 50 to 200 lines of code. Some enigmas can be written as fun one-liners, while some require a more structured approach that is better described with Object Oriented Programming.

The second parts take the premises of the first and expand on those, usually by adding some plot twists or by simply increasing the complexity of the challenge.

So, here are some tips and reflections on how those second parts were designed and how to solve them:

  1. Simple evolutions: the task you're up to asks you a different thing than the first part, so you have to rewrite some of the original code and add the required logic to complete the second part.
  2. Hardcore optimizations: sometimes in the second part you're asked to execute the same algorithm you built a bigger number of times. It seems innocent enough but since the input grows exponentially every iteration you have to optimize where you can. You'll find out that the original solution, that took way less than a second would take years on the second part, so you have to optimize the execution of code.
  3. Optimize first: sometimes you'll optimize the first part, so the second part will take advantage of the first part and solve at the same speed.
  4. Unravel the bundle: sometimes you'll be asked to solve what apparently seems a full Enigma machine. So you have to start unraveling the messy bundle, once you find the right thread to pull the pieces will start to make sense to you. Perhaps this will take you in an entirely different direction than the first part.

I must admit that since I decided to write this little entry I managed to solve 4 second parts, now I feel a little less stupid.

Back