Done day 25
[advent-of-code-21.git] / problems / day25.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 25 - Advent of Code 2021</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?28"/>
9 <link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?0" title="High Contrast"/>
10 <link rel="shortcut icon" href="/favicon.png"/>
11 <script>window.addEventListener('click', function(e,s,r){if(e.target.nodeName==='CODE'&&e.detail===3){s=window.getSelection();s.removeAllRanges();r=document.createRange();r.selectNodeContents(e.target);s.addRange(r);}});</script>
12 </head><!--
13
14
15
16
17 Oh, hello! Funny seeing you here.
18
19 I appreciate your enthusiasm, but you aren't going to find much down here.
20 There certainly aren't clues to any of the puzzles. The best surprises don't
21 even appear in the source until you unlock them for real.
22
23 Please be careful with automated requests; I'm not a massive company, and I can
24 only take so much traffic. Please be considerate so that everyone gets to play.
25
26 If you're curious about how Advent of Code works, it's running on some custom
27 Perl code. Other than a few integrations (auth, analytics, social media), I
28 built the whole thing myself, including the design, animations, prose, and all
29 of the puzzles.
30
31 The puzzles are most of the work; preparing a new calendar and a new set of
32 puzzles each year takes all of my free time for 4-5 months. A lot of effort
33 went into building this thing - I hope you're enjoying playing it as much as I
34 enjoyed making it for you!
35
36 If you'd like to hang out, I'm @ericwastl on Twitter.
37
38 - Eric Wastl
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 <body>
91 <header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2021/about">[About]</a></li><li><a href="/2021/events">[Events]</a></li><li><a href="https://teespring.com/stores/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2021/settings">[Settings]</a></li><li><a href="/2021/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <a href="/2021/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">50*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">0xffff&amp;</span><a href="/2021">2021</a><span class="title-event-wrap"></span></h1><nav><ul><li><a href="/2021">[Calendar]</a></li><li><a href="/2021/support">[AoC++]</a></li><li><a href="/2021/sponsors">[Sponsors]</a></li><li><a href="/2021/leaderboard">[Leaderboard]</a></li><li><a href="/2021/stats">[Stats]</a></li></ul></nav></div></header>
92
93 <div id="sidebar">
94 <div id="sponsor"><div class="quiet">Our <a href="/2021/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://getsturdy.com/aoc" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Sturdy</a> - Real-time version control for code. Watch us live!</div></div>
95 </div><!--/sidebar-->
96
97 <main>
98 <style>article *[title]{border-bottom:1px dotted #ffff66;}</style><article class="day-desc"><h2>--- Day 25: Sea Cucumber ---</h2><p>This is it: the bottom of the ocean trench, the last place the sleigh keys could be. Your submarine's experimental antenna <em>still isn't boosted enough</em> to detect the keys, but they <em>must</em> be here. All you need to do is <em>reach the seafloor</em> and find them.</p>
99 <p>At least, you'd touch down on the seafloor if you could; unfortunately, it's completely covered by two large herds of <a href="https://en.wikipedia.org/wiki/Sea_cucumber" target="_blank">sea cucumbers</a>, and there isn't an open space large enough for your submarine.</p>
100 <p>You suspect that the Elves must have done this before, because just then you discover the phone number of a deep-sea marine biologist on a handwritten note taped to the wall of the submarine's cockpit.</p>
101 <p>"Sea cucumbers? Yeah, they're probably hunting for food. But don't worry, they're predictable critters: they move in perfectly straight lines, only moving forward when there's space to do so. They're actually quite polite!"</p>
102 <p>You explain that you'd like to predict when you could land your submarine.</p>
103 <p>"Oh that's easy, they'll eventually pile up and leave enough space for-- wait, did you say submarine? And the only place with that many sea cucumbers would be at the very bottom of the Mariana--" You hang up the phone.</p>
104 <p>There are two herds of sea cucumbers sharing the same region; one always moves <em>east</em> (<code>&gt;</code>), while the other always moves <em>south</em> (<code>v</code>). Each location can contain at most one sea cucumber; the remaining locations are <em>empty</em> (<code>.</code>). The submarine helpfully generates a map of the situation (your puzzle input). For example:</p>
105 <pre><code>v...&gt;&gt;.vv&gt;
106 .vv&gt;&gt;.vv..
107 &gt;&gt;.&gt;v&gt;...v
108 &gt;&gt;v&gt;&gt;.&gt;.v.
109 v&gt;v.vv.v..
110 &gt;.&gt;&gt;..v...
111 .vv..&gt;.&gt;v.
112 v.v..&gt;&gt;v.v
113 ....v..v.&gt;
114 </code></pre>
115 <p>Every <em>step</em>, the sea cucumbers in the east-facing herd attempt to move forward one location, then the sea cucumbers in the south-facing herd attempt to move forward one location. When a herd moves forward, every sea cucumber in the herd first simultaneously considers whether there is a sea cucumber in the adjacent location it's facing (even another sea cucumber facing the same direction), and then every sea cucumber facing an empty location simultaneously moves into that location.</p>
116 <p>So, in a situation like this:</p>
117 <pre><code>...&gt;&gt;&gt;&gt;&gt;...</code></pre>
118 <p>After one step, only the rightmost sea cucumber would have moved:</p>
119 <pre><code>...&gt;&gt;&gt;&gt;.&gt;..</code></pre>
120 <p>After the next step, two sea cucumbers move:</p>
121 <pre><code>...&gt;&gt;&gt;.&gt;.&gt;.</code></pre>
122 <p>During a single step, the east-facing herd moves first, then the south-facing herd moves. So, given this situation:</p>
123 <pre><code>..........
124 .&gt;v....v..
125 .......&gt;..
126 ..........
127 </code></pre>
128 <p>After a single step, of the sea cucumbers on the left, only the south-facing sea cucumber has moved (as it wasn't out of the way in time for the east-facing cucumber on the left to move), but both sea cucumbers on the right have moved (as the east-facing sea cucumber moved out of the way of the south-facing sea cucumber):</p>
129 <pre><code>..........
130 .&gt;........
131 ..v....v&gt;.
132 ..........
133 </code></pre>
134 <p>Due to <em>strong water currents</em> in the area, sea cucumbers that move off the right edge of the map appear on the left edge, and sea cucumbers that move off the bottom edge of the map appear on the top edge. Sea cucumbers always check whether their destination location is empty before moving, even if that destination is on the opposite side of the map:</p>
135 <pre><code>Initial state:
136 ...&gt;...
137 .......
138 ......&gt;
139 v.....&gt;
140 ......&gt;
141 .......
142 ..vvv..
143
144 After 1 step:
145 ..vv&gt;..
146 .......
147 &gt;......
148 v.....&gt;
149 &gt;......
150 .......
151 ....v..
152
153 After 2 steps:
154 ....v&gt;.
155 ..vv...
156 .&gt;.....
157 ......&gt;
158 v&gt;.....
159 .......
160 .......
161
162 After 3 steps:
163 ......&gt;
164 ..v.v..
165 ..&gt;v...
166 &gt;......
167 ..&gt;....
168 v......
169 .......
170
171 After 4 steps:
172 &gt;......
173 ..v....
174 ..&gt;.v..
175 .&gt;.v...
176 ...&gt;...
177 .......
178 v......
179 </code></pre>
180 <p>To find a safe place to land your submarine, the sea cucumbers need to stop moving. Again consider the first example:</p>
181 <pre><code>Initial state:
182 v...&gt;&gt;.vv&gt;
183 .vv&gt;&gt;.vv..
184 &gt;&gt;.&gt;v&gt;...v
185 &gt;&gt;v&gt;&gt;.&gt;.v.
186 v&gt;v.vv.v..
187 &gt;.&gt;&gt;..v...
188 .vv..&gt;.&gt;v.
189 v.v..&gt;&gt;v.v
190 ....v..v.&gt;
191
192 After 1 step:
193 ....&gt;.&gt;v.&gt;
194 v.v&gt;.&gt;v.v.
195 &gt;v&gt;&gt;..&gt;v..
196 &gt;&gt;v&gt;v&gt;.&gt;.v
197 .&gt;v.v...v.
198 v&gt;&gt;.&gt;vvv..
199 ..v...&gt;&gt;..
200 vv...&gt;&gt;vv.
201 &gt;.v.v..v.v
202
203 After 2 steps:
204 &gt;.v.v&gt;&gt;..v
205 v.v.&gt;&gt;vv..
206 &gt;v&gt;.&gt;.&gt;.v.
207 &gt;&gt;v&gt;v.&gt;v&gt;.
208 .&gt;..v....v
209 .&gt;v&gt;&gt;.v.v.
210 v....v&gt;v&gt;.
211 .vv..&gt;&gt;v..
212 v&gt;.....vv.
213
214 After 3 steps:
215 v&gt;v.v&gt;.&gt;v.
216 v...&gt;&gt;.v.v
217 &gt;vv&gt;.&gt;v&gt;..
218 &gt;&gt;v&gt;v.&gt;.v&gt;
219 ..&gt;....v..
220 .&gt;.&gt;v&gt;v..v
221 ..v..v&gt;vv&gt;
222 v.v..&gt;&gt;v..
223 .v&gt;....v..
224
225 After 4 steps:
226 v&gt;..v.&gt;&gt;..
227 v.v.&gt;.&gt;.v.
228 &gt;vv.&gt;&gt;.v&gt;v
229 &gt;&gt;.&gt;..v&gt;.&gt;
230 ..v&gt;v...v.
231 ..&gt;&gt;.&gt;vv..
232 &gt;.v.vv&gt;v.v
233 .....&gt;&gt;vv.
234 vvv&gt;...v..
235
236 After 5 steps:
237 vv&gt;...&gt;v&gt;.
238 v.v.v&gt;.&gt;v.
239 &gt;.v.&gt;.&gt;.&gt;v
240 &gt;v&gt;.&gt;..v&gt;&gt;
241 ..v&gt;v.v...
242 ..&gt;.&gt;&gt;vvv.
243 .&gt;...v&gt;v..
244 ..v.v&gt;&gt;v.v
245 v.v.&gt;...v.
246
247 ...
248
249 After 10 steps:
250 ..&gt;..&gt;&gt;vv.
251 v.....&gt;&gt;.v
252 ..v.v&gt;&gt;&gt;v&gt;
253 v&gt;.&gt;v.&gt;&gt;&gt;.
254 ..v&gt;v.vv.v
255 .v.&gt;&gt;&gt;.v..
256 v.v..&gt;v&gt;..
257 ..v...&gt;v.&gt;
258 .vv..v&gt;vv.
259
260 ...
261
262 After 20 steps:
263 v&gt;.....&gt;&gt;.
264 &gt;vv&gt;.....v
265 .&gt;v&gt;v.vv&gt;&gt;
266 v&gt;&gt;&gt;v.&gt;v.&gt;
267 ....vv&gt;v..
268 .v.&gt;&gt;&gt;vvv.
269 ..v..&gt;&gt;vv.
270 v.v...&gt;&gt;.v
271 ..v.....v&gt;
272
273 ...
274
275 After 30 steps:
276 .vv.v..&gt;&gt;&gt;
277 v&gt;...v...&gt;
278 &gt;.v&gt;.&gt;vv.&gt;
279 &gt;v&gt;.&gt;.&gt;v.&gt;
280 .&gt;..v.vv..
281 ..v&gt;..&gt;&gt;v.
282 ....v&gt;..&gt;v
283 v.v...&gt;vv&gt;
284 v.v...&gt;vvv
285
286 ...
287
288 After 40 steps:
289 &gt;&gt;v&gt;v..v..
290 ..&gt;&gt;v..vv.
291 ..&gt;&gt;&gt;v.&gt;.v
292 ..&gt;&gt;&gt;&gt;vvv&gt;
293 v.....&gt;...
294 v.v...&gt;v&gt;&gt;
295 &gt;vv.....v&gt;
296 .&gt;v...v.&gt;v
297 vvv.v..v.&gt;
298
299 ...
300
301 After 50 steps:
302 ..&gt;&gt;v&gt;vv.v
303 ..v.&gt;&gt;vv..
304 v.&gt;&gt;v&gt;&gt;v..
305 ..&gt;&gt;&gt;&gt;&gt;vv.
306 vvv....&gt;vv
307 ..v....&gt;&gt;&gt;
308 v&gt;.......&gt;
309 .vv&gt;....v&gt;
310 .&gt;v.vv.v..
311
312 ...
313
314 After 55 steps:
315 ..&gt;&gt;v&gt;vv..
316 ..v.&gt;&gt;vv..
317 ..&gt;&gt;v&gt;&gt;vv.
318 ..&gt;&gt;&gt;&gt;&gt;vv.
319 v......&gt;vv
320 v&gt;v....&gt;&gt;v
321 vvv...&gt;..&gt;
322 &gt;vv.....&gt;.
323 .&gt;v.vv.v..
324
325 After 56 steps:
326 ..&gt;&gt;v&gt;vv..
327 ..v.&gt;&gt;vv..
328 ..&gt;&gt;v&gt;&gt;vv.
329 ..&gt;&gt;&gt;&gt;&gt;vv.
330 v......&gt;vv
331 v&gt;v....&gt;&gt;v
332 vvv....&gt;.&gt;
333 &gt;vv......&gt;
334 .&gt;v.vv.v..
335
336 After 57 steps:
337 ..&gt;&gt;v&gt;vv..
338 ..v.&gt;&gt;vv..
339 ..&gt;&gt;v&gt;&gt;vv.
340 ..&gt;&gt;&gt;&gt;&gt;vv.
341 v......&gt;vv
342 v&gt;v....&gt;&gt;v
343 vvv.....&gt;&gt;
344 &gt;vv......&gt;
345 .&gt;v.vv.v..
346
347 After 58 steps:
348 ..&gt;&gt;v&gt;vv..
349 ..v.&gt;&gt;vv..
350 ..&gt;&gt;v&gt;&gt;vv.
351 ..&gt;&gt;&gt;&gt;&gt;vv.
352 v......&gt;vv
353 v&gt;v....&gt;&gt;v
354 vvv.....&gt;&gt;
355 &gt;vv......&gt;
356 .&gt;v.vv.v..
357 </code></pre>
358 <p>In this example, the sea cucumbers stop moving after <code><em>58</em></code> steps.</p>
359 <p>Find somewhere safe to land your submarine. <em>What is the first step on which no sea cucumbers move?</em></p>
360 </article>
361 <p>Your puzzle answer was <code>435</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>Suddenly, the experimental antenna control console lights up:</p>
362 <pre><code><em>Sleigh keys detected!</em></code></pre>
363 <p>According to the console, the keys are <em>directly under the submarine</em>. <span title="Thanks to the deep-sea marine biologist, who apparently works at the Biham-Middleton-Levine oceanic research institute.">You landed</span> right on them! Using a robotic arm on the submarine, you move the sleigh keys into the airlock.</p>
364 <p>Now, you just need to get them to Santa in time to save Christmas! You check your clock - it <em>is</em> Christmas. There's no way you can get them back to the surface in time.</p>
365 <p>Just as you start to lose hope, you notice a button on the sleigh keys: <em>remote start</em>. You can start the sleigh from the bottom of the ocean! You just need some way to <em>boost the signal</em> from the keys so it actually reaches the sleigh. Good thing the submarine has that experimental antenna! You'll definitely need <em class="star">50 stars</em> to boost it that far, though.</p>
366 <p>The experimental antenna control console lights up again:</p>
367 <pre><code><em>Energy source detected.
368 Integrating energy source from device "sleigh keys"...done.
369 Installing device drivers...done.
370 Recalibrating experimental antenna...done.
371 Boost strength due to matching signal phase: <em class="star">1 star</em>
372 </em></code></pre>
373 <p>Only <em class="star">49 stars</em> to go.</p>
374 </article>
375 <form method="post" action="25/answer"><input type="hidden" name="level" value="2"/><input type="hidden" name="answer" value="0"/><p>If you like, you can <input type="submit" value="[Remotely Start The Sleigh Again]"/>.</p></form>
376 <p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
377 <p>At this point, all that is left is for you to <a href="/2021">admire your Advent calendar</a>.</p>
378 <p>If you still want to see it, you can <a href="25/input" target="_blank">get your puzzle input</a>.</p>
379 <p>You can also <span class="share">[Share<span class="share-content">on
380 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Sea+Cucumber%22+%2D+Day+25+%2D+Advent+of+Code+2021&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2021%2Fday%2F25&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
381 <a href="javascript:void(0);" onclick="var mastodon_instance=prompt('Mastodon Instance / Server Name?'); if(typeof mastodon_instance==='string' && mastodon_instance.length){this.href='https://'+mastodon_instance+'/share?text=I%27ve+completed+%22Sea+Cucumber%22+%2D+Day+25+%2D+Advent+of+Code+2021+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2021%2Fday%2F25'}else{return false;}" target="_blank">Mastodon</a
382 ></span>]</span> this puzzle.</p>
383 </main>
384
385 <!-- ga -->
386 <script>
387 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
388 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
389 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
390 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
391 ga('create', 'UA-69522494-1', 'auto');
392 ga('set', 'anonymizeIp', true);
393 ga('send', 'pageview');
394 </script>
395 <!-- /ga -->
396 </body>
397 </html>