**Content warning:**AoC 2021 day 8 spoilers

# Advent of Code 2021, Day 8

Day 8 looks to be a fun bit of deductive reasoning. Should be interesting!

The premise: the wires for our seven-segment displays got jumbled up somehow. The puzzle text blames this on the sperm whale, but this is a weirdly specific sort of failure.

I think it’s more likely that whichever elf wired these things up in the first place was having an off day and not really paying enough attention. You know how it goes in crunch time. Too much to do and too little time to do it in, and nice-to-have things like the submarine get rushed in favour of the important stuff like getting all the toys ready.

It’s all right, elf buddy. We’ve all been there.

It’s pretty clear that part 2 is going to be a full decoder, but part 1 only asks us to count up how many 1s, 4s, 7s, and 8s there are in the display output. It even tells you what to look for. That’s so trivial I’m going to skip over it here and go straight to part 2.

Ah, now this is the fun part. Each line of puzzle input comes with all the segments that’ll light up for each number, but in a random order, so that we’ve always got enough information to decode that line.

The reason part 1 was so simple was to give us a starting point: the number 1 is the only number with two segments lit, 7 is the only one with 3 (they’re using the 7 variant that doesn’t have segment b lit), 4 is the only one with 4, and 8 is, of course, the only number with all 7 segments lit.

So we’ve got four numbers already. We can work out which sequences correspond to the other numbers by which segments they share with each other.

- Start with the six-segment numbers: 0, 6, 9. One of 1’s segments doesn’t appear in 6 but both appear in 0 and 9, so we can use this to identify 6.
- Of the remaining two, all of 4’s segments appear in 9 but not in 0, so we can use this to identify 9.
- The one remaining six-segment number is 0.
- Next, we can find the three five-segment numbers: 2, 3, 5. All of 3 and 5’s segments appear in 9, but not in 2, so we can use this to identify 2.
- Similarly, all of 5’s segments appear in 6 but not 3, so we can use this to identify 6.
- And finally, by process of elimination, the one remaining unknown value is 3.

There are other ways of doing this, of course. A slightly more difficult challenge would have been to work out the segment mappings - wire a lights segment f or whatever - but it’s only a few extra steps.

In the end, it has us test our decoded numbers by reading the actual output of the displays and adding them up, once again a trivial task once you have the decoded numbers.

So day 8 was a nice breather. Not especially difficult, but still more engaging than yesterday’s puzzle was.