Hello everyone, it’s time for your Advent of Code 2021 Day 8 log. Started the challenge, spent under an hour writing part one while taking notes for today’s cruise log. Lost all notes because the laptop got unplugged while I left it unattended as I focused on my day job.
Decided to leave it as work would start soon and went to work for a bit. End of the sprint, calls
almost non-stop till almost 2 pm. Got some more work done as I got an idea I wanted to try for
the bit I’m working on at the moment. Eventually headed off for lunch a bit before 3 pm,
girlfriend made some turkey with roasted sweet potatoes. I welcomed these warmly. Rested my eyes a few minutes then got back to my personal laptop left unattended the whole morning.
It was asleep which makes sense, it’s been half a day since last touching it. I use the usual soft touches to wake it up. Nothing. Then I realise, it’s unplugged. The horror. All my notes about
the challenge and other notes taken for this post, gone forever. I turn it back on and get back on this headscratcher.
Upon returning, I figured the fastest way forward is to put prints everywhere sensible. After a few minutes of that, I spotted that we could make certain deductions that would allow detecting the right segment mappings. Using the default mappings from the problem statement we can use letters from a to g to define the segments and map them to the random set of letters also comprising values from a to g. Using the characteristics we have from 1, 4, 7 and 8 we can deduct the translated values of those characters.
The easiest ones were a, c and f then I’d have to loop through the other letters and test some conditions to check whether they’d fit the description of other characters. From there, I wrote a detection method for b, c, d, e and g. It almost worked. Most unit tests passed except for 3.
I tweaked the code a little bit to have more deduction based constraints, none of the tests passed but I felt like I was still on the right path. Now instead of multiple values missing, only one was absent. The value for the b segment. I ran all the tests again. The code maps all the segment keys except for b. This occurred for every single test case in part two.
Seeing that I only had half of my lunch break left I decided to brute-force this and loop over the candidate keys that weren’t picked knowing there would always only be one that has to match b and set it as the mapping for the b segment. Then it all turned green. I ran the input and it worked. Now I can enjoy the last minutes of my break playing Smite and I will enjoy tonight’s Christmas party. Yet another Christmas miracle.
Thank you for reading my Advent of Code 2021 Day 8 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 7 log right here.