Now uses a Reader monad
[advent-of-code-19.git] / problems / day15.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 15 - Advent of Code 2019</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?24"/>
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 </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 a massive company, and I can
23 only take 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 are most of the work; preparing a new calendar and a new set of
31 puzzles each year takes all of my free time for 4-5 months. A lot of effort
32 went into building this thing - I hope you're enjoying playing it as much as I
33 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="/2019/about">[About]</a></li><li><a href="/2019/events">[Events]</a></li><li><a href="https://teespring.com/adventofcode-2019" target="_blank">[Shop]</a></li><li><a href="/2019/settings">[Settings]</a></li><li><a href="/2019/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <a href="/2019/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">30*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">/*</span><a href="/2019">2019</a><span class="title-event-wrap">*/</span></h1><nav><ul><li><a href="/2019">[Calendar]</a></li><li><a href="/2019/support">[AoC++]</a></li><li><a href="/2019/sponsors">[Sponsors]</a></li><li><a href="/2019/leaderboard">[Leaderboard]</a></li><li><a href="/2019/stats">[Stats]</a></li></ul></nav></div></header>
91
92 <div id="sidebar">
93 <div id="sponsor"><div class="quiet">Our <a href="/2019/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://ximed.es/aoc" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Ximedes</a> - Help us write elegant, secure, and performant software that enables payments worldwide. We&apos;re hiring in the Netherlands and Serbia!</div></div>
94 </div><!--/sidebar-->
95
96 <main>
97 <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>
98 <article class="day-desc"><h2>--- Day 15: Oxygen System ---</h2><p>Out here in deep space, many things can go wrong. Fortunately, many of those things have <span title="Which indicator lights indicate when the indicator lights have failed?">indicator lights</span>. Unfortunately, one of those lights is lit: the oxygen system for part of the ship has failed!</p>
99 <p>According to the readouts, the oxygen system must have failed days ago after a rupture in oxygen tank two; that section of the ship was automatically sealed once oxygen levels went dangerously low. A single remotely-operated <em>repair droid</em> is your only option for fixing the oxygen system.</p>
100 <p>The Elves' care package included an <a href="9">Intcode</a> program (your puzzle input) that you can use to remotely control the repair droid. By running that program, you can direct the repair droid to the oxygen system and fix the problem.</p>
101 <p>The remote control program executes the following steps in a loop forever:</p>
102 <ul>
103 <li>Accept a <em>movement command</em> via an input instruction.</li>
104 <li>Send the movement command to the repair droid.</li>
105 <li>Wait for the repair droid to finish the movement operation.</li>
106 <li>Report on the <em>status</em> of the repair droid via an output instruction.</li>
107 </ul>
108 <p>Only four <em>movement commands</em> are understood: north (<code>1</code>), south (<code>2</code>), west (<code>3</code>), and east (<code>4</code>). Any other command is invalid. The movements differ in direction, but not in distance: in a long enough east-west hallway, a series of commands like <code>4,4,4,4,3,3,3,3</code> would leave the repair droid back where it started.</p>
109 <p>The repair droid can reply with any of the following <em>status</em> codes:</p>
110 <ul>
111 <li><code>0</code>: The repair droid hit a wall. Its position has not changed.</li>
112 <li><code>1</code>: The repair droid has moved one step in the requested direction.</li>
113 <li><code>2</code>: The repair droid has moved one step in the requested direction; its new position is the location of the oxygen system.</li>
114 </ul>
115 <p>You don't know anything about the area around the repair droid, but you can figure it out by watching the status codes.</p>
116 <p>For example, we can draw the area using <code>D</code> for the droid, <code>#</code> for walls, <code>.</code> for locations the droid can traverse, and empty space for unexplored locations. Then, the initial state looks like this:</p>
117 <pre><code>
118
119 D
120
121
122 </code></pre>
123 <p>To make the droid go north, send it <code>1</code>. If it replies with <code>0</code>, you know that location is a wall and that the droid didn't move:</p>
124 <pre><code>
125 #
126 D
127
128
129 </code></pre>
130 <p>To move east, send <code>4</code>; a reply of <code>1</code> means the movement was successful:</p>
131 <pre><code>
132 #
133 .D
134
135
136 </code></pre>
137 <p>Then, perhaps attempts to move north (<code>1</code>), south (<code>2</code>), and east (<code>4</code>) are all met with replies of <code>0</code>:</p>
138 <pre><code>
139 ##
140 .D#
141 #
142
143 </code></pre>
144 <p>Now, you know the repair droid is in a dead end. Backtrack with <code>3</code> (which you already know will get a reply of <code>1</code> because you already know that location is open):</p>
145 <pre><code>
146 ##
147 D.#
148 #
149
150 </code></pre>
151 <p>Then, perhaps west (<code>3</code>) gets a reply of <code>0</code>, south (<code>2</code>) gets a reply of <code>1</code>, south again (<code>2</code>) gets a reply of <code>0</code>, and then west (<code>3</code>) gets a reply of <code>2</code>:</p>
152 <pre><code>
153 ##
154 #..#
155 D.#
156 #
157 </code></pre>
158 <p>Now, because of the reply of <code>2</code>, you know you've found the <em>oxygen system</em>! In this example, it was only <code><em>2</em></code> moves away from the repair droid's starting position.</p>
159 <p><em>What is the fewest number of movement commands</em> required to move the repair droid from its starting position to the location of the oxygen system?</p>
160 </article>
161 <p>Your puzzle answer was <code>220</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>You quickly repair the oxygen system; oxygen gradually fills the area.</p>
162 <p>Oxygen starts in the location containing the repaired oxygen system. It takes <em>one minute</em> for oxygen to spread to all open locations that are adjacent to a location that already contains oxygen. Diagonal locations are <em>not</em> adjacent.</p>
163 <p>In the example above, suppose you've used the droid to explore the area fully and have the following map (where locations that currently contain oxygen are marked <code>O</code>):</p>
164 <pre><code> ##
165 #..##
166 #.#..#
167 #.O.#
168 ###
169 </code></pre>
170 <p>Initially, the only location which contains oxygen is the location of the repaired oxygen system. However, after one minute, the oxygen spreads to all open (<code>.</code>) locations that are adjacent to a location containing oxygen:</p>
171 <pre><code> ##
172 #..##
173 #.#..#
174 #OOO#
175 ###
176 </code></pre>
177 <p>After a total of two minutes, the map looks like this:</p>
178 <pre><code> ##
179 #..##
180 #O#O.#
181 #OOO#
182 ###
183 </code></pre>
184 <p>After a total of three minutes:</p>
185 <pre><code> ##
186 #O.##
187 #O#OO#
188 #OOO#
189 ###
190 </code></pre>
191 <p>And finally, the whole region is full of oxygen after a total of four minutes:</p>
192 <pre><code> ##
193 #OO##
194 #O#OO#
195 #OOO#
196 ###
197 </code></pre>
198 <p>So, in this example, all locations contain oxygen after <code><em>4</em></code> minutes.</p>
199 <p>Use the repair droid to get a complete map of the area. <em>How many minutes will it take to fill with oxygen?</em></p>
200 </article>
201 <p>Your puzzle answer was <code>334</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
202 <p>At this point, you should <a href="/2019">return to your Advent calendar</a> and try another puzzle.</p>
203 <p>If you still want to see it, you can <a href="15/input" target="_blank">get your puzzle input</a>.</p>
204 <p>You can also <span class="share">[Share<span class="share-content">on
205 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Oxygen+System%22+%2D+Day+15+%2D+Advent+of+Code+2019&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2019%2Fday%2F15&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
206 <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+%22Oxygen+System%22+%2D+Day+15+%2D+Advent+of+Code+2019+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2019%2Fday%2F15'}else{return false;}" target="_blank">Mastodon</a
207 ></span>]</span> this puzzle.</p>
208 </main>
209
210 <!-- ga -->
211 <script>
212 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
213 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
214 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
215 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
216 ga('create', 'UA-69522494-1', 'auto');
217 ga('set', 'anonymizeIp', true);
218 ga('send', 'pageview');
219 </script>
220 <!-- /ga -->
221 </body>
222 </html>