Top of the morning Irish friends and everyone else. No time to go out there to praise the guys that created what has now become the microwave. We won’t praise the hypothermia researchers either for it is time for your Advent of Code 2022 Day 2 cruising log.
As the tradition continues, this second day was a tad more confusing than the last. It could be that day 1 was the participation trophy day. However, it could also be that my body is getting used to waking up this early and the brain takes time to follow suit. Either way, the problem wasn’t the most challenging even though it took me a whole 28 minutes to solve part 1.
Generally, this happens when not (or mis)reading the problem statement and as it turns out I missed a key bit. Well, not exactly missed, more like read it but failed to translate it into my original solution. The worst thing is that the unit test I wrote for the example case went through.
The thing is, these are purposefully unreliable. What I mean by that is that they should pass if you write the right solution. But they may also pass if you missed edge cases which I did. At least when the first submission failed I remembered that and went back to read the problem statement. Which today is about cheating at rock, paper, scissors, hence the title of the post. The edge cases were there hiding in plain sight, so I wrote a couple of extra tests which failed as expected.
At that point I went back and analysed my logic. Turns out I only needed to adjust one part of the code and voila! Tests all green. From there I run the input through the code, submit the solution and collect the first star of the day. Easy life.
Next is part two which I chose to read a couple of times before changing a single line of code. Since in the early days, speed has little consequences for well structured code I went for that. I copied a couple methods while reusing the rest of what I had for part one. The sample case was there and I had one method well isolated that I had to replace in order to fit the updated problem. Instant green test, followed by an instant second star which validates my part two within four minutes of submitting part one.
Thank you for reading my Advent of Code 2022 Day 2 log, I will see you tomorrow. As usual I will push the code to my repo for this year on Github.
Cover by Pavel Danilyuk: