Skip to content

The Advent of Code 2021 Day 13, Nautical origami

Posted in Advent of Code

Hello everyone, it’s time for your Advent of Code 2021 Day 13 cruise log. Today’s challenge was the visual answer one. One where unit tests can be written but not as quickly as you wish to get rid of the challenge fast enough. Let’s jump right into it!

Reading the problem description, it felt like I would have an easy time solving this. Reading through, I need to do some exploring and modifying of a grid. In this one, we’re dealing with some origami shenanigans where we need to fold the grid over and over. Once we did all our folding, sensible shapes should appear.

The parsing of the grid alongside the folding operations was quite straightforward. For the first part, we only had to validate how many dots will be visible after executing the first folding instruction. The problem statement seems to indicate so long as my translating method is good, we will be fine. Even for the second part.

From there, I peeked out the real input data and noticed that the first instruction was different from the one of the sample input. This means that I actually have to implement both folding methods to have my unit test and actual answer working. After a few minutes of typing away, I run my unit test to validate the code against the sample input and it goes green. Right away I run the code against the real input and clutch my first star of the day.

Now part two is only about running all the folding operations and reading what characters will appear once we print the grid. I already wrote a printing method in case the first part would have yielded a red test run. At this point, all I need to do is set up my second part method to run all folding operations. This is what appeared:

advent of code 2021 day 13 part two fail
The first attempt at part two didn’t turn as expected

Nothing, a whole bunch of nothing! The should have worked. My paper run-throughs worked, the theory worked for the transformation so what gives? I run the part two unit test with a printed answer since the first part points that after running all the folding operations, printing the grid should draw a square. And guess what? I see a flippin’ square! Exactly the same as the sample input from part one. I even copied the output to search it on the day 13 webpage and it matched.

No need to say this is an impasse, I am ready to give up momentarily. There are about thirty minutes before 8 am and I do want to work out before work begins. I have no idea how to debug this since there is no further clue I can work with. Still, I decide to spend another ten minutes on this before moving on with my day and picking this up after work.

I close my eyes for a moment, maybe a few seconds or minutes, not quite sure. I go back over the problem statement, nothing pops out. Now I feel like my brain is drying, I get a sip of water, then another then finish my litre-jug. There are about twenty-five minutes left to 8. Something obvious must be there, or something that should be there but isn’t.

This is when I realise something. The folding line. In the real input data, the folding instructions seem to always follow a pattern. The next value N would follow this suite N = 2*(N-1)-1. At this point, I kinda realised that the problem statement mentions that dots will never appear on a fold line. Yet my algorithm would start filling values from the fold line rather than the next creating a shift.

advent of code 2021 day 13 input fold instructions
Folding instructions

Now I know what is wrong and I can adjust and use the skip the fold line in my new grid filling. After the change, the unit tests still passed and I could still see a square. It’s seventeen to 8, I run my changes against the input. It doesn’t look like much but is legible.

advent of code 2021 day 13 part two result
My input’s answer: EAHKRECP

Finally, star number 26. Less painful than previous years but it feels more like a Christmas miracle than an illustration of my problem-solving skills.

advent of code 2021 day 13 getting 26 stars

Thank you for reading my Advent of Code 2021 Day 13 log, I will see you tomorrow. As usual, I will push the code to my repo for this year on Github. Feel free to check out my Day 12 log right here.

Photo by Miguel Á. Padriñán from Pexels

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: