You barely reach the safety of the cave when the whale smashes into the cave mouth, collapsing it. Sensors indicate another exit to this cave at a much greater depth, so you have no choice but to press on.

Time to fall into a rage, then a depression, then mania, fake my way aboard another submarine, whip the crew into a bloodthirsty frenzy and scour the ocean in the name of revenge. Or, you know, weep a few manly tears and retire quietly to the country. Coin flip, really.

I had a lot of fun with this one. I’d classify it as “logic puzzle”. The problem:

There are many 7-segment displays that are malfunctioning; the inputs have been randomly assigned to the outputs. Our task was to figure out the mapping. Below is an example of the input for a single display; to the left of the pipe are the input patterns for the 10 unique digits. To the right are the numbers we have to decode.

Example test input:

acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab | cdfeb fcadb cdfeb cdbaf


Output digit mapping:

  0:      1:      2:      3:      4:
 aaaa    ....    aaaa    aaaa    ....
b    c  .    c  .    c  .    c  b    c
b    c  .    c  .    c  .    c  b    c
 ....    ....    dddd    dddd    dddd
e    f  .    f  e    .  .    f  .    f
e    f  .    f  e    .  .    f  .    f
 gggg    ....    gggg    gggg    ....

  5:      6:      7:      8:      9:
 aaaa    aaaa    aaaa    aaaa    aaaa
b    .  b    .  .    c  b    c  b    c
b    .  b    .  .    c  b    c  b    c
 dddd    dddd    ....    dddd    dddd
.    f  e    f  .    f  e    f  .    f
.    f  e    f  .    f  e    f  .    f
 gggg    gggg    ....    gggg    gggg


There’s some features of the input that make this possible to solve. One, some output digits have a unique length (1,4,7, and 8). This is part one of the problem; simply count the number of 1s,4s,7s, and 8s in the output section. Part two is to decode and sum all the output numbers. Part one holds a clue to part two; there’s more usable information to be found by looking at the output patterns. I decided to treat this as a logic puzzle, and wrote ‘Wrote’ in this case means illegibly scribbling slightly similar tables 3 times before I got anything useful out of it. down the table below.

  a b c d e f g Sum
0 x x x   x x x 6
1     x     x   2
2 x   x x x   x 5
3 x   x x   x x 5
4   x   x   x   4
5 x x   x   x x 5
6 x x   x x x x 6
7 x   x     x   3
8 x x x x x x x 7
9 x x x x   x x 6
Sum 8 6 8 7 4 9 7  

The sum across the X direction shows the unique info hand-fed to us in part 1. The sum in the Y direction is new info; the characters that map to b, e, and f occur 6, 4, and 9 times in the input, respectively. Now, all we need is a way of telling apart a and c, and d and g. We know from looking at the output mapping that a is in seven and not in one. We also know that g is in eight, but not in four. Since we know which input strings are one, seven, eight, and one, we have all the information we need to make a full mapping table from input to output characters.

Code