1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
--- Day 8: Seven Segment Search ---
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.
As your submarine slowly makes its way through the cave system, you notice that the four-digit
seven-segment displays in your submarine are malfunctioning; they must have been damaged during the
escape. You'll be in a lot of trouble without them, so you'd better figure out what's wrong.
Each digit of a seven-segment display is rendered by turning on or off any of seven segments named a
through g:
0: 1: 2: 3: 4:
[1m[37maaaa[0m .... [1m[37maaaa aaaa[0m ....
[1m[37mb c[0m . [1m[37mc[0m . [1m[37mc[0m . [1m[37mc b c[0m
[1m[37mb c[0m . [1m[37mc[0m . [1m[37mc[0m . [1m[37mc b c[0m
.... .... [1m[37mdddd dddd dddd[0m
[1m[37me f[0m . [1m[37mf e[0m . . [1m[37mf[0m . [1m[37mf[0m
[1m[37me f[0m . [1m[37mf e[0m . . [1m[37mf[0m . [1m[37mf[0m
[1m[37mgggg[0m .... [1m[37mgggg gggg[0m ....
5: 6: 7: 8: 9:
[1m[37maaaa aaaa aaaa aaaa aaaa[0m
[1m[37mb[0m . [1m[37mb[0m . . [1m[37mc b c b c[0m
[1m[37mb[0m . [1m[37mb[0m . . [1m[37mc b c b c[0m
[1m[37mdddd dddd[0m .... [1m[37mdddd dddd[0m
. [1m[37mf e f[0m . [1m[37mf e f[0m . [1m[37mf[0m
. [1m[37mf e f[0m . [1m[37mf e f[0m . [1m[37mf[0m
[1m[37mgggg gggg[0m .... [1m[37mgggg gggg[0m
So, to render a 1, only segments c and f would be turned on; the rest would be off. To render a 7,
only segments a, c, and f would be turned on.
The problem is that the signals which control the segments have been mixed up on each display. The
submarine is still trying to display numbers by producing output on signal wires a through g, but
those wires are connected to segments [1m[37mrandomly[0m. Worse, the wire/segment connections are mixed up
separately for each four-digit display! (All of the digits [1m[37mwithin[0m a display use the same
connections, though.)
So, you might know that only signal wires b and g are turned on, but that doesn't mean
[1m[37msegments[0m b and g are turned on: the only digit that uses two segments is 1, so it must mean segments
c and f are meant to be on. With just that information, you still can't tell which wire (b/g) goes
to which segment (c/f). For that, you'll need to collect more information.
For each display, you watch the changing signals for a while, make a note of [1m[37mall ten unique signal
patterns[0m you see, and then write down a single [1m[37mfour digit output value[0m (your puzzle input). Using
the signal patterns, you should be able to work out which pattern corresponds to which digit.
For example, here is what you might see in a single entry in your notes:
acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab |
cdfeb fcadb cdfeb cdbaf
(The entry is wrapped here to two lines so it fits; in your notes, it will all be on a single line.)
Each entry consists of ten [1m[37munique signal patterns[0m, a | delimiter, and finally the [1m[37mfour digit output
value[0m. Within an entry, the same wire/segment connections are used (but you don't know what the
connections actually are). The unique signal patterns correspond to the ten different ways the
submarine tries to render a digit using the current wire/segment connections. Because 7 is the only
digit that uses three segments, dab in the above example means that to render a 7, signal lines d,
a, and b are on. Because 4 is the only digit that uses four segments, eafb means that to render a 4,
signal lines e, a, f, and b are on.
Using this information, you should be able to work out which combination of signal wires corresponds
to each of the ten digits. Then, you can decode the four digit output value. Unfortunately, in the
above example, all of the digits in the output value (cdfeb fcadb cdfeb cdbaf) use five segments and
are more difficult to deduce.
For now, [1m[37mfocus on the easy digits[0m. Consider this larger example:
be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb |
[1m[37mfdgacbe[0m cefdb cefbgd [1m[37mgcbe[0m
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec |
fcgedb [1m[37mcgb[0m [1m[37mdgebacf[0m [1m[37mgc[0m
fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef |
[1m[37mcg[0m [1m[37mcg[0m fdcagb [1m[37mcbg[0m
fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega |
efabcd cedba gadfec [1m[37mcb[0m
aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga |
[1m[37mgecf[0m [1m[37megdcabf[0m [1m[37mbgf[0m bfgea
fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf |
[1m[37mgebdcfa[0m [1m[37mecba[0m [1m[37mca[0m [1m[37mfadegcb[0m
dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf |
[1m[37mcefg[0m dcbef [1m[37mfcge[0m [1m[37mgbcadfe[0m
bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd |
[1m[37med[0m bcgafe cdgba cbgef
egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg |
[1m[37mgbdfcae[0m [1m[37mbgc[0m [1m[37mcg[0m [1m[37mcgb[0m
gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc |
[1m[37mfgae[0m cfgab [1m[37mfg[0m bagce
Because the digits 1, 4, 7, and 8 each use a unique number of segments, you should be able to tell
which combinations of signals correspond to those digits. Counting [1m[37monly digits in the output
values[0m (the part after | on each line), in the above example, there are [1m[37m26[0m instances of digits that
use a unique number of segments (highlighted above).
[1m[37mIn the output values, how many times do digits 1, 4, 7, or 8 appear?[0m
|