Day 8
[advent-of-code-2021.git] / day08 / task.txt
1 --- Day 8: Seven Segment Search ---
2 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.
3
4 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.
5
6 Each digit of a seven-segment display is rendered by turning on or off any of seven segments named a through g:
7
8   0:      1:      2:      3:      4:
9  aaaa    ....    aaaa    aaaa    ....
10 b    c  .    c  .    c  .    c  b    c
11 b    c  .    c  .    c  .    c  b    c
12  ....    ....    dddd    dddd    dddd
13 e    f  .    f  e    .  .    f  .    f
14 e    f  .    f  e    .  .    f  .    f
15  gggg    ....    gggg    gggg    ....
16
17   5:      6:      7:      8:      9:
18  aaaa    aaaa    aaaa    aaaa    aaaa
19 b    .  b    .  .    c  b    c  b    c
20 b    .  b    .  .    c  b    c  b    c
21  dddd    dddd    ....    dddd    dddd
22 .    f  e    f  .    f  e    f  .    f
23 .    f  e    f  .    f  e    f  .    f
24  gggg    gggg    ....    gggg    gggg
25 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.
26
27 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 randomly. Worse, the wire/segment connections are mixed up separately for each four-digit display! (All of the digits within a display use the same connections, though.)
28
29 So, you might know that only signal wires b and g are turned on, but that doesn't mean segments 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.
30
31 For each display, you watch the changing signals for a while, make a note of all ten unique signal patterns you see, and then write down a single four digit output value (your puzzle input). Using the signal patterns, you should be able to work out which pattern corresponds to which digit.
32
33 For example, here is what you might see in a single entry in your notes:
34
35 acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab |
36 cdfeb fcadb cdfeb cdbaf
37 (The entry is wrapped here to two lines so it fits; in your notes, it will all be on a single line.)
38
39 Each entry consists of ten unique signal patterns, a | delimiter, and finally the four digit output value. 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.
40
41 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.
42
43 For now, focus on the easy digits. Consider this larger example:
44
45 be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb |
46 fdgacbe cefdb cefbgd gcbe
47 edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec |
48 fcgedb cgb dgebacf gc
49 fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef |
50 cg cg fdcagb cbg
51 fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega |
52 efabcd cedba gadfec cb
53 aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga |
54 gecf egdcabf bgf bfgea
55 fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf |
56 gebdcfa ecba ca fadegcb
57 dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf |
58 cefg dcbef fcge gbcadfe
59 bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd |
60 ed bcgafe cdgba cbgef
61 egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg |
62 gbdfcae bgc cg cgb
63 gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc |
64 fgae cfgab fg bagce
65 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 only digits in the output values (the part after | on each line), in the above example, there are 26 instances of digits that use a unique number of segments (highlighted above).
66
67 In the output values, how many times do digits 1, 4, 7, or 8 appear?
68
69 Your puzzle answer was 247.
70
71 --- Part Two ---
72 Through a little deduction, you should now be able to determine the remaining digits. Consider again the first example above:
73
74 acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab |
75 cdfeb fcadb cdfeb cdbaf
76 After some careful analysis, the mapping between signal wires and segments only make sense in the following configuration:
77
78  dddd
79 e    a
80 e    a
81  ffff
82 g    b
83 g    b
84  cccc
85 So, the unique signal patterns would correspond to the following digits:
86
87 acedgfb: 8
88 cdfbe: 5
89 gcdfa: 2
90 fbcad: 3
91 dab: 7
92 cefabd: 9
93 cdfgeb: 6
94 eafb: 4
95 cagedb: 0
96 ab: 1
97 Then, the four digits of the output value can be decoded:
98
99 cdfeb: 5
100 fcadb: 3
101 cdfeb: 5
102 cdbaf: 3
103 Therefore, the output value for this entry is 5353.
104
105 Following this same process for each entry in the second, larger example above, the output value of each entry can be determined:
106
107 fdgacbe cefdb cefbgd gcbe: 8394
108 fcgedb cgb dgebacf gc: 9781
109 cg cg fdcagb cbg: 1197
110 efabcd cedba gadfec cb: 9361
111 gecf egdcabf bgf bfgea: 4873
112 gebdcfa ecba ca fadegcb: 8418
113 cefg dcbef fcge gbcadfe: 4548
114 ed bcgafe cdgba cbgef: 1625
115 gbdfcae bgc cg cgb: 8717
116 fgae cfgab fg bagce: 4315
117 Adding all of the output values in this larger example produces 61229.
118
119 For each entry, determine all of the wire/segment connections and decode the four-digit output values. What do you get if you add up all of the output values?
120
121 Your puzzle answer was 933305.
122
123 Both parts of this puzzle are complete! They provide two gold stars: **
124
125 At this point, you should return to your Advent calendar and try another puzzle.
126
127 If you still want to see it, you can get your puzzle input.
128
129 You can also [Share] this puzzle.