Skip to content

The Advent of Code 2022 Day 7 log: spaced out

Posted in Advent of Code

Nothing can be said to be sure in this world except that death, taxes and Day 7 will sting. Today’s puzzle took much more time than I expected despite getting a double expresso at 5 am on the dot. Welcome to my Advent of Code 2022 Day 7 log.

Just like in 2021, 2020 and every previous year I took part in, the difficulty sharply increases on the seventh day. Sometimes it goes back down, others it is the point some get off the Advent of Code train. I feel like, if not for some double espresso, I would have taken twice the time to complete today’s puzzle. Fortunately, my fiancee took some time yesterday to sort out our beans-to-cup machine so I could get some.

Sure, the coffee took some time to take effect as I drank it while reading the problem statement but it did the job I think. The problem statement itself was fairly straightforward. We get a text with some bash commands. These commands are navigation and directory display commands. We use these and their “outputs” to generate a directory tree that will contain files and subdirectories. Eventually, we need to make a calculation based on the space within that directory tree. Straightforward.

What was not straightforward was the parsing of the commands. While it took me half an hour to write the first version of my solution, it took me almost an extra hour to have code which built the directory tree. The worst part of this is that the first attempt was pretty close to my final output. But I kept getting stuck as the final line of the input was processed ad infinitum.

I couldn’t see why, whenever I would change the parsing logic, I would mess it all up. When I reverted it, I would return to that solution which parses everything but gets stuck in an infinite loop. I figured I could just have a random increment in my outer loop when not recognizing a certain pattern. And yet, I refused to do it because it felt dirty. A whole fifty minutes going back and forth that way.

Eventually, I see the light and decide to use that random increment. The unit test passed but the input submission failed. What gives? I guess that the coffee hadn’t kicked in yet when I read the part about the calculation we needed to do. I think it’s accurate considering my calculation returned the exact opposite of the expected result.

Once I read the statement again, I updated my test, fortunately, the fix was a one-liner. The new test passes. My submission goes through. One hour, thirty-one minutes and fifty-seven seconds in. Finally, my first star of the day for my longest part-one resolution yet.

Now comes the second part. We need to do a slightly different calculation using that same directory tree. From there I rejoiced that my original code worked great for this. I had domain-ish classes, a parsing class, and an interface for some not-so-fancy polymorphism in there.

The coffee had more than kicked in by now and once I figured out what that new code needed to do it was game over. Sixteen minutes and twelve seconds later I submitted the solution to the second part. First in my company leaderboard to do so, which is quite the feat considering how skilled my peers are.

As a result, I still sit atop that leaderboard with some more space between myself and the second. This will serve my ranking well as difficulty ramps up in the coming days. And yes, most of them also wake up before 5 am because we take this challenge seriously. Just like everything else. Now I’m off for some cardio before heading to the office.

Thank you for reading my Advent of Code 2022 Day 7 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.

Be First to Comment

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    %d bloggers like this: