Taking advantage of a neat trick for using $ rather than a lambda
[advent-of-code-17.git] / problems / day09.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 9 - Advent of Code 2017</title>
6 <!--[if lt IE 9]><script src="/static/html5.js"></script><![endif]-->
7 <link href='//fonts.googleapis.com/css?family=Source+Code+Pro:300&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
8 <link rel="stylesheet" type="text/css" href="/static/style.css?11"/>
9 <link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?0" title="High Contrast"/>
10 <link rel="shortcut icon" href="/favicon.ico?2"/>
11 </head><!--
12
13
14
15
16 Oh, hello! Funny seeing you here.
17
18 I appreciate your enthusiasm, but you aren't going to find much down here.
19 There certainly aren't clues to any of the puzzles. The best surprises don't
20 even appear in the source until you unlock them for real.
21
22 Please be careful with automated requests; I'm not Google, and I can only take
23 so much traffic. Please be considerate so that everyone gets to play.
24
25 If you're curious about how Advent of Code works, it's running on some custom
26 Perl code. Other than a few integrations (auth, analytics, ads, social media),
27 I built the whole thing myself, including the design, animations, prose, and
28 all of the puzzles.
29
30 The puzzles probably took the longest; the easiest ones took an hour or two
31 each, but the harder ones took 4-5 hours, and a few even longer than that. A
32 lot of effort went into building this thing - I hope you're enjoying playing it
33 as much as I enjoyed making it for you!
34
35 If you'd like to hang out, I'm @ericwastl on Twitter.
36
37 - Eric Wastl
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 <body>
90 <header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2017/about">[About]</a></li><li><a href="/2017/support">[AoC++]</a></li><li><a href="/2017/events">[Events]</a></li><li><a href="/2017/settings">[Settings]</a></li><li><a href="/2017/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <span class="supporter">(AoC++)</span> <span class="star-count">18*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">/*</span><a href="/2017">2017</a><span class="title-event-wrap">*/</span></h1><nav><ul><li><a href="/2017">[Calendar]</a></li><li><a href="/2017/leaderboard">[Leaderboard]</a></li><li><a href="/2017/stats">[Stats]</a></li><li><a href="/2017/sponsors">[Sponsors]</a></li></ul></nav></div></header>
91
92 <div id="sidebar">
93 <div id="sponsor"><div class="quiet">Our <a href="/2017/sponsors">sponsors</a> help make Advent of Code possible:</div><p><a href="http://winton.com/" target="_blank" onclick="if(ga)ga('send','event','sponsor','click',this.href);" rel="noopener">Winton</a> - a data science and investment management company</p></div>
94 <div id="ad">
95 <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
96 <!-- Advent of Code Wide Skyscraper -->
97 <ins class="adsbygoogle"
98 style="display:inline-block;width:160px;height:600px"
99 data-ad-client="ca-pub-9420604735624631"
100 data-ad-slot="8014013294"></ins>
101 <script>
102 (adsbygoogle = window.adsbygoogle || []).push({});
103 </script>
104 </div><!--/ad-->
105 </div><!--/sidebar-->
106
107 <main>
108 <article class="day-desc"><h2>--- Day 9: Stream Processing ---</h2><p>A large stream blocks your path. According to the locals, it's not safe to <span title="&quot;Don't cross the streams!&quot;, they yell, even though there's only one. They seem to think they're hilarious.">cross the stream</span> at the moment because it's full of <em>garbage</em>. You look down at the stream; rather than water, you discover that it's a <em>stream of characters</em>.</p>
109 <p>You sit for a while and record part of the stream (your puzzle input). The characters represent <em>groups</em> - sequences that begin with <code>{</code> and end with <code>}</code>. Within a group, there are zero or more other things, separated by commas: either another <em>group</em> or <em>garbage</em>. Since groups can contain other groups, a <code>}</code> only closes the <em>most-recently-opened unclosed group</em> - that is, they are nestable. Your puzzle input represents a single, large group which itself contains many smaller ones.</p>
110 <p>Sometimes, instead of a group, you will find <em>garbage</em>. Garbage begins with <code>&lt;</code> and ends with <code>&gt;</code>. Between those angle brackets, almost any character can appear, including <code>{</code> and <code>}</code>. <em>Within</em> garbage, <code>&lt;</code> has no special meaning.</p>
111 <p>In a futile attempt to clean up the garbage, some program has <em>canceled</em> some of the characters within it using <code>!</code>: inside garbage, <em>any</em> character that comes after <code>!</code> should be <em>ignored</em>, including <code>&lt;</code>, <code>&gt;</code>, and even another <code>!</code>.</p>
112 <p>You don't see any characters that deviate from these rules. Outside garbage, you only find well-formed groups, and garbage always terminates according to the rules above.</p>
113 <p>Here are some self-contained pieces of garbage:</p>
114 <ul>
115 <li><code>&lt;&gt;</code>, empty garbage.</li>
116 <li><code>&lt;random characters&gt;</code>, garbage containing random characters.</li>
117 <li><code>&lt;&lt;&lt;&lt;&gt;</code>, because the extra <code>&lt;</code> are ignored.</li>
118 <li><code>&lt;{!&gt;}&gt;</code>, because the first <code>&gt;</code> is canceled.</li>
119 <li><code>&lt;!!&gt;</code>, because the second <code>!</code> is canceled, allowing the <code>&gt;</code> to terminate the garbage.</li>
120 <li><code>&lt;!!!&gt;&gt;</code>, because the second <code>!</code> and the first <code>&gt;</code> are canceled.</li>
121 <li><code>&lt;{o"i!a,&lt;{i&lt;a&gt;</code>, which ends at the first <code>&gt;</code>.</li>
122 </ul>
123 <p>Here are some examples of whole streams and the number of groups they contain:</p>
124 <ul>
125 <li><code>{}</code>, <code>1</code> group.</li>
126 <li><code>{{{}}}</code>, <code>3</code> groups.</li>
127 <li><code>{{},{}}</code>, also <code>3</code> groups.</li>
128 <li><code>{{{},{},{{}}}}</code>, <code>6</code> groups.</li>
129 <li><code>{&lt;{},{},{{}}&gt;}</code>, <code>1</code> group (which itself contains garbage).</li>
130 <li><code>{&lt;a&gt;,&lt;a&gt;,&lt;a&gt;,&lt;a&gt;}</code>, <code>1</code> group.</li>
131 <li><code>{{&lt;a&gt;},{&lt;a&gt;},{&lt;a&gt;},{&lt;a&gt;}}</code>, <code>5</code> groups.</li>
132 <li><code>{{&lt;!&gt;},{&lt;!&gt;},{&lt;!&gt;},{&lt;a&gt;}}</code>, <code>2</code> groups (since all but the last <code>&gt;</code> are canceled).</li>
133 </ul>
134 <p>Your goal is to find the total score for all groups in your input. Each group is assigned a <em>score</em> which is one more than the score of the group that immediately contains it. (The outermost group gets a score of <code>1</code>.)</p>
135 <ul>
136 <li><code>{}</code>, score of <code>1</code>.</li>
137 <li><code>{{{}}}</code>, score of <code>1 + 2 + 3 = 6</code>.</li>
138 <li><code>{{},{}}</code>, score of <code>1 + 2 + 2 = 5</code>.</li>
139 <li><code>{{{},{},{{}}}}</code>, score of <code>1 + 2 + 3 + 3 + 3 + 4 = 16</code>.</li>
140 <li><code>{&lt;a&gt;,&lt;a&gt;,&lt;a&gt;,&lt;a&gt;}</code>, score of <code>1</code>.</li>
141 <li><code>{{&lt;ab&gt;},{&lt;ab&gt;},{&lt;ab&gt;},{&lt;ab&gt;}}</code>, score of <code>1 + 2 + 2 + 2 + 2 = 9</code>.</li>
142 <li><code>{{&lt;!!&gt;},{&lt;!!&gt;},{&lt;!!&gt;},{&lt;!!&gt;}}</code>, score of <code>1 + 2 + 2 + 2 + 2 = 9</code>.</li>
143 <li><code>{{&lt;a!&gt;},{&lt;a!&gt;},{&lt;a!&gt;},{&lt;ab&gt;}}</code>, score of <code>1 + 2 = 3</code>.</li>
144 </ul>
145 <p><em>What is the total score</em> for all groups in your input?</p>
146 </article>
147 <p>Your puzzle answer was <code>11089</code>.</p><article class="day-desc"><h2>--- Part Two ---</h2><p>Now, you're ready to remove the garbage.</p>
148 <p>To prove you've removed it, you need to count all of the characters within the garbage. The leading and trailing <code>&lt;</code> and <code>&gt;</code> don't count, nor do any canceled characters or the <code>!</code> doing the canceling.</p>
149 <ul>
150 <li><code>&lt;&gt;</code>, <code>0</code> characters.</li>
151 <li><code>&lt;random characters&gt;</code>, <code>17</code> characters.</li>
152 <li><code>&lt;&lt;&lt;&lt;&gt;</code>, <code>3</code> characters.</li>
153 <li><code>&lt;{!&gt;}&gt;</code>, <code>2</code> characters.</li>
154 <li><code>&lt;!!&gt;</code>, <code>0</code> characters.</li>
155 <li><code>&lt;!!!&gt;&gt;</code>, <code>0</code> characters.</li>
156 <li><code>&lt;{o"i!a,&lt;{i&lt;a&gt;</code>, <code>10</code> characters.</li>
157 </ul>
158 <p><em>How many non-canceled characters are within the garbage</em> in your puzzle input?</p>
159 </article>
160 <p>Your puzzle answer was <code>5288</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
161 <p>At this point, you should <a href="/2017">return to your advent calendar</a> and try another puzzle.</p>
162 <p>If you still want to see it, you can <a href="9/input" target="_blank">get your puzzle input</a>.</p>
163 <p>You can also <span class="share">[Share<span class="share-content">on
164 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Stream+Processing%22+%2D+Day+9+%2D+Advent+of+Code+2017&amp;url=http%3A%2F%2Fadventofcode%2Ecom%2F2017%2Fday%2F9&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
165 <a href="https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2F2017%2Fday%2F9" target="_blank">Google+</a>
166 <a href="http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2F2017%2Fday%2F9&amp;title=I%27ve+completed+%22Stream+Processing%22+%2D+Day+9+%2D+Advent+of+Code+2017" target="_blank">Reddit</a
167 ></span>]</span> this puzzle.</p>
168 </main>
169
170 <!-- ga -->
171 <script>
172 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
173 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
174 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
175 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
176 ga('create', 'UA-69522494-1', 'auto');
177 ga('send', 'pageview');
178 </script>
179 <!-- /ga -->
180 </body>
181 </html>