Skip to content

The Advent of Code 2022 Day 10 log: pixel perfect

Posted in Advent of Code

Morning guys, I hope you’ve enjoyed you’re enjoying your Saturday. I personally took a little break to chill after completing today’s puzzle. Hopefully, you didn’t expect this post to drop at 7 am, the time I woke up today. Welcome to my Advent of Code 2022 Day 10 cruise log.

This day started as they all do. I open my eyes and look around in the darkness. I take a moment to be thankful for my life, the things I do and the people I interact with. Then I glance at my phone. 6.56 am. Someday I might return to the top 100 finishers of a puzzle but today is not that day. Especially with the release of ChatGPT a week ago. I hear that a good amount of people taking top spots use it to solve puzzles. Not sure how well it would work for harder puzzles like today but for day 2 I saw a demo and it wrote an optimised solution for it.

But even if this goal becomes unattainable, if not for my lateness waking up, by the power of machine learning, I’ll still aim for that. I’ve only ever done it a couple of times over the past few years. Generally, I manage to do so towards the latter days so it might be evidence that bots only take you so far.

Back to today’s problem. Since woke up late, I skipped the coffee part which I regretted while reading the problem statement. Since my brain still indulged in fuzziness, I read it at least three times. Eventually, I grasped it and started coding. Within about twenty minutes, I ran a test using the large example provided. It goes red.

As usual, when this happens, I write a smaller test around the area I suspect contains a bug. It does return an unexpected result. Reading again the problem with the examples, I realise I swapped two steps in my code. After fixing this issue, I eventually get my tests to pass and submit my first answer of the day. All under forty minutes. Time for part two.

Now the problem looks completely different but fortunately, the modelling I chose for the first part came in handy here. I kept the data structure unchanged and could simply process it to get the answer to the second part.

Here, we need to generate an input that will draw something. Using the large test input it should yield a random drawing like below:

advent of code 2022 day 10 part two test output
Expected test output

I wrote my part two test accordingly:

advent of code 2022 day 10 part two unit test
my test

Originally, I thought I could generate such that drawing on the fly. However, as I started writing that code I realised this wouldn’t work. Going over the problem description again, I realise I got a few things wrong on the rules around the drawing. Rules around what is a pixel, how I can find which pixel to draw into and so on.

Eventually, I realise quickly that I need a two-dimensional array to store my values and then update values for which I turn on the pixels. Turning on a pixel requires replacing a . character with a # character.

I delete the part two code that I wrote so far and go back from scratch. Reading the problem again to ensure I understand exactly which value represents what and how to update my screen. After another twenty-ish minutes, I’ve got something that works. The unit test passes.

I run the app again and see something that at first looks kinda wrong. After a few seconds, I realise that I’m not fully awake yet. I close my eyes, then open them again. Now I see them. The letters revealed by my algorithm: PAPKFKEJ.

The secret message was PAPKFKEJ

I submit my answer and get the 20th star of this Advent of Code. My company leaderboard top spot is safe, but for how long?

At last, I can enjoy a chilled day starting with a workout, followed by breakfast with a peak World Cup game. While we will enjoy this France vs England confrontation in my mostly quiet living room. From there we’ll go celebrate France qualifying with our France jerseys in London streets. That’ll be a good time. Also if you don’t see an entry for day 11 and the days after that, take it that I underestimated the stabbiness of London.

Thank you for reading my Advent of Code 2022 Day 10 log, I should 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: