Hello, there and welcome to my Advent of Code 2020 Day 14 cruise log. After an actual 8-hour long night of sleep, I felt in a better shape to tackle today’s challenge. Today, the problem master chose to give us an easier challenge to solve. If not, then maybe it is that a night of sleep reaps benefits after thirty-three hours without it. I definitely expected this to happen.
Good night of sleep: Check
— Jean-Dominique Nguele (@CodingNagger) December 14, 2020
5 am start, let’s goooooo! #AdventOfCode pic.twitter.com/Ujgi0gPSbb
Our task today required me to parse a text input into a set of bitmasks and write instructions. After processing these, we would have certain values written into a memory structure. Once the program “executed”, we would then return the sum of the mapped values. Pretty straightforward in theory, but the practice turned out different, but only by my fault.
I wrote the first test to validate that I could apply the bitmask requirements on binary numbers. It felt like a wise choice since it is a key part of the exercise. From there, I went on a roll and started creating methods alongside their tests. Everything passed, except for the example test. Each small method I wrote passed its tests, however, I decided to extend one. I wrote a test to validate that the bitmask applied correctly to another example value and it passed as well.
This is where I switched to my print and debug mode, the oldest trick in the book. I could feel that somewhere, something got lost in translation and this is the best way to figure where. The first place to start was the bitmask application method, I added prints for the input and output parameters. The unknown became obvious as the issue revealed itself. My part one code passed a decimal string value instead of a binary one. Then I realised I didn’t use my decimal to binary number method at all. After adding it, the part one test finally passed but the input failed with the unholy out of bounds error.
Why? Why does it always happen to be? Well, as often in this Advent of Code, we’re dealing with a classic case of PEBCAK. As an expert in the domain, I managed to figure the flaw pretty quick. I made the assumption that we would have only one bitmask to parse but looking at the input there is a multitude. At that point, I need to rewrite my first part logic but luckily, the methods used can remain the same. Eventually, after correcting that flow and adding a new test to validate the fix, I successfully processed my input before 6 am. Time for the sequel.
This one felt like a trap, an accident waiting to happen. The core of it is the same as the first part except that the bitmask is applied to the memory address with a bonus. Bonus that usually means recursion and 2^N time complexity. Not today, I recalled that I can use stacks for that but for the rest, there is still Amex. Once more, I took out pen and paper then walked through the logic until I had something coherent.
Eventually, I finished implementing my second part but the test failed to pass. Yes, again. As it turns out, I forgot that this time I’m not summing up binary strings but decimal ones after duplicating my part one code. Upon parsing the string with the right method, the test passed but the input didn’t. Too high a value, the site said. I could not imagine any reason why it wouldn’t work. Maybe if I go sacrifice a lamb on the Southbank the input will pass, unfortunately, it rarely works. What often works on the other hand is checking my program’s entry point which called the part one method instead of the second. After dealing with that negligence, I took my 28th star this year a few minutes before 7 am.
Thank you for reading my Advent of Code 2020 Day 14 cruise log, I will see you tomorrow, maybe. In the meantime, you can check out my Go Cloud series about building and deploying a Golang app to AWS. Also, I will push my code on Github at CodingNagger/advent-of-code-2020 so feel free to check it out but not before you’ve done the challenge yourself. Bye!
Photo by Roman Koval from Pexels