Alright, another day waking up at 4.50 am. Well, 4.56 actually, but still early enough to grab an espresso. I know for a fact this will be a long day. First I need to tackle this challenge. Then I write this blog post. Next, I grab breakfast before heading to work. After that, I play not one, but two 5-a-side football games before catching the last half of Croatia-Argentina with my football mates. So enough chit-chat, time to jump into my Advent of Code 2022 day 13 log.
After reading the puzzle prompt, I felt some familiarity with the problem and its shape. It looks like one of these Russian doll problems which come back each year. While the topic and result to achieve are similar, I could not recall for the life of me when I last saw one in AoC. Unfortunately, I would need to write that logic from scratch so I got into it. Let’s set a Russian doll tag on this post for next year’s run. That way, when it shows up again, I know how to find my old code to save some time.
Basically, we’ve got some data to parse by pairs and each pair represent containers. These containers might contain either a number or other containers. We need to write some logic to compare these and determine a certain result from that. Sounds straightforward because it mostly is. The biggest hurdle is parsing that thing. At least I recall that much.
Today will be different, it’s not a weekend day so I cannot afford to take more than two or three hours to solve this. So I started modelling the data and writing code while thinking through the parsing logic. I glanced at the various leaderboards I’m into. The office leaderboard still looks good, still sitting atop it. However, in the private leaderboard that I created after the previous post, I am dead last. Only two of us in there so not much shame there but still.
It threw me off for a sec but I got back to coding. After about an hour, I finished writing my first draft of parsing logic. Loads of heavy debugging to find and squash bugs as I found them. I wrote a bunch of toString()
implementations to ensure that reconstructed structures matched what I parsed. I found a bug here and there, Eventually, I dealt with all these and my tests passed.
However, as I’ve come to expect at this point, we’re past day 10 after all, the real input run yielded the wrong result. Back to the code. I went back through the problem statement and then through the code. Still nothing.
From there I scan the real input and find a case that is not listed in the sample input. Maybe I’ve got my hidden bug. I write another test for it and it fails! Just as expected. I kinda guessed where the issue was before I finished writing that test. You know the old adage, trust but verify, and I did just that. Next, I wrote the fix and the test passed. Feeling on a roll, I run the code against my real input and collect my 25th star, getting me exactly at the halfway point of this Advent of Code.
Time for part two, I spent extra time designing the structure in the first part hoping it would fit the latter part. I felt quite relieved when I saw that I did it right. Now, I could add a minimal amount of code to answer the question of this part. The validation test for it passed right away, I ran the code against the input and collected my second star of the day. All within fifteen minutes. Plenty of time left to enjoy staying warm at home before heading into a -3C London towards the office.
Thank you for reading my Advent of Code 2022 Day 13 log, I will see you tomorrow. If you want to check out my previous entry, you can do so here. You can even read my entries from last year there. As usual, I will push the code to my repo for this year on Github. Also, if you want to test yourself against my AoC 2022 run, I’ve created a private leaderboard. The invite code is 382952-d065ee7a
. Join, if you dare.
Cover by cottonbro studio