comparison 2017/day09/problem @ 34:049fb8e56025

Add problem statements and inputs
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Tue, 09 Jan 2018 21:51:44 -0500
parents
children
comparison
equal deleted inserted replaced
33:bc652fa0a645 34:049fb8e56025
1 --- Day 9: Stream Processing ---
2
3 A large stream blocks your path. According to the locals, it's not
4 safe to cross the stream at the moment because it's full of garbage.
5 You look down at the stream; rather than water, you discover that it's
6 a stream of characters.
7
8 You sit for a while and record part of the stream (your puzzle input).
9 The characters represent groups - sequences that begin with { and end
10 with }. Within a group, there are zero or more other things, separated
11 by commas: either another group or garbage. Since groups can contain
12 other groups, a } only closes the most-recently-opened unclosed group
13 - that is, they are nestable. Your puzzle input represents a single,
14 large group which itself contains many smaller ones.
15
16 Sometimes, instead of a group, you will find garbage. Garbage begins
17 with < and ends with >. Between those angle brackets, almost any
18 character can appear, including { and }. Within garbage, < has no
19 special meaning.
20
21 In a futile attempt to clean up the garbage, some program has canceled
22 some of the characters within it using !: inside garbage, any
23 character that comes after ! should be ignored, including <, >, and
24 even another !.
25
26 You don't see any characters that deviate from these rules. Outside
27 garbage, you only find well-formed groups, and garbage always
28 terminates according to the rules above.
29
30 Here are some self-contained pieces of garbage:
31
32 <>, empty garbage.
33
34 <random characters>, garbage containing random characters.
35
36 <<<<>, because the extra < are ignored.
37
38 <{!>}>, because the first > is canceled.
39
40 <!!>, because the second ! is canceled, allowing the > to
41 terminate the garbage.
42
43 <!!!>>, because the second ! and the first > are canceled.
44
45 <{o"i!a,<{i<a>, which ends at the first >.
46
47 Here are some examples of whole streams and the number of groups they contain:
48
49 {}, 1 group.
50
51 {{{}}}, 3 groups.
52
53 {{},{}}, also 3 groups.
54
55 {{{},{},{{}}}}, 6 groups.
56
57 {<{},{},{{}}>}, 1 group (which itself contains garbage).
58
59 {<a>,<a>,<a>,<a>}, 1 group.
60
61 {{<a>},{<a>},{<a>},{<a>}}, 5 groups.
62
63 {{<!>},{<!>},{<!>},{<a>}}, 2 groups (since all but the last > are
64 canceled).
65
66
67 Your goal is to find the total score for all groups in your input.
68 Each group is assigned a score which is one more than the score of the
69 group that immediately contains it. (The outermost group gets a score
70 of 1.)
71
72 {}, score of 1.
73
74 {{{}}}, score of 1 + 2 + 3 = 6.
75
76 {{},{}}, score of 1 + 2 + 2 = 5.
77
78 {{{},{},{{}}}}, score of 1 + 2 + 3 + 3 + 3 + 4 = 16.
79
80 {<a>,<a>,<a>,<a>}, score of 1.
81
82 {{<ab>},{<ab>},{<ab>},{<ab>}}, score of 1 + 2 + 2 + 2 + 2 = 9.
83
84 {{<!!>},{<!!>},{<!!>},{<!!>}}, score of 1 + 2 + 2 + 2 + 2 = 9.
85
86 {{<a!>},{<a!>},{<a!>},{<ab>}}, score of 1 + 2 = 3.
87
88 What is the total score for all groups in your input?
89
90 Your puzzle answer was 12803.
91
92 --- Part Two ---
93
94 Now, you're ready to remove the garbage.
95
96 To prove you've removed it, you need to count all of the characters
97 within the garbage. The leading and trailing < and > don't count, nor
98 do any canceled characters or the ! doing the canceling.
99
100 <>, 0 characters.
101
102 <random characters>, 17 characters.
103
104 <<<<>, 3 characters.
105
106 <{!>}>, 2 characters.
107
108 <!!>, 0 characters.
109
110 <!!!>>, 0 characters.
111
112 <{o"i!a,<{i<a>, 10 characters.
113
114 How many non-canceled characters are within the garbage in your puzzle
115 input?
116
117 Your puzzle answer was 6425.
118
119 Both parts of this puzzle are complete! They provide two gold stars: **