Day 13
[advent-of-code-18.git] / problems / day13.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 13 - Advent of Code 2018</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?18"/>
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 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 are most of the work; the easiest ones take 3-4 hours each, but the
31 harder ones take 6-8 hours, and a few even longer than that. 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="/2018/about">[About]</a></li><li><a href="/2018/events">[Events]</a></li><li><a href="https://teespring.com/adventofcode" target="_blank">[Shop]</a></li><li><a href="/2018/settings">[Settings]</a></li><li><a href="/2018/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <a href="/2018/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">26*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">y(</span><a href="/2018">2018</a><span class="title-event-wrap">)</span></h1><nav><ul><li><a href="/2018">[Calendar]</a></li><li><a href="/2018/support">[AoC++]</a></li><li><a href="/2018/sponsors">[Sponsors]</a></li><li><a href="/2018/leaderboard">[Leaderboard]</a></li><li><a href="/2018/stats">[Stats]</a></li></ul></nav></div></header>
91
92 <div id="sidebar">
93 <div id="sponsor"><div class="quiet">Our <a href="/2018/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://clubhouse.io/?utm_source=spon&amp;utm_medium=ch&amp;utm_campaign=aoc2018" target="_blank" onclick="if(ga)ga('send','event','sponsor','click',this.href);" rel="noopener">Clubhouse</a> - The first project management platform for software development that brings everyone on every team together to build better products. AoC participants get two free months by signing up at r.clbh.se/mze9q9P Also, we're hiring!</div></div>
94 </div><!--/sidebar-->
95
96 <main>
97 <article class="day-desc"><h2>--- Day 13: Mine Cart Madness ---</h2><p>A crop of this size requires significant logistics to transport produce, soil, fertilizer, and so on. The Elves are very busy pushing things around in <em>carts</em> on some kind of rudimentary system of tracks they've come up with.</p>
98 <p>Seeing as how cart-and-track systems don't appear in recorded history for another 1000 years, the Elves seem to be making this up as they go along. They haven't even figured out how to avoid collisions yet.</p>
99 <p>You map out the tracks (your puzzle input) and see where you can help.</p>
100 <p>Tracks consist of straight paths (<code>|</code> and <code>-</code>), curves (<code>/</code> and <code>\</code>), and intersections (<code>+</code>). Curves connect exactly two perpendicular pieces of track; for example, this is a closed loop:</p>
101 <pre><code>/----\
102 | |
103 | |
104 \----/
105 </code></pre>
106 <p>Intersections occur when two perpendicular paths cross. At an intersection, a cart is capable of turning left, turning right, or continuing straight. Here are two loops connected by two intersections:</p>
107 <pre><code>/-----\
108 | |
109 | /--+--\
110 | | | |
111 \--+--/ |
112 | |
113 \-----/
114 </code></pre>
115 <p>Several <em>carts</em> are also on the tracks. Carts always face either up (<code>^</code>), down (<code>v</code>), left (<code>&lt;</code>), or right (<code>&gt;</code>). (On your initial map, the track under each cart is a straight path matching the direction the cart is facing.)</p>
116 <p>Each time a cart has the option to turn (by arriving at any intersection), it turns <em>left</em> the first time, goes <em>straight</em> the second time, turns <em>right</em> the third time, and then repeats those directions starting again with <em>left</em> the fourth time, <em>straight</em> the fifth time, and so on. This process is independent of the particular intersection at which the cart has arrived - that is, the cart has no per-intersection memory.</p>
117 <p>Carts all move at the same speed; they take turns moving a single step at a time. They do this based on their <em>current location</em>: carts on the top row move first (acting from left to right), then carts on the second row move (again from left to right), then carts on the third row, and so on. Once each cart has moved one step, the process repeats; each of these loops is called a <em>tick</em>.</p>
118 <p>For example, suppose there are two carts on a straight track:</p>
119 <pre><code>| | | | |
120 v | | | |
121 | v v | |
122 | | | v X
123 | | ^ ^ |
124 ^ ^ | | |
125 | | | | |
126 </code></pre>
127 <p>First, the top cart moves. It is facing down (<code>v</code>), so it moves down one square. Second, the bottom cart moves. It is facing up (<code>^</code>), so it moves up one square. Because all carts have moved, the first tick ends. Then, the process repeats, starting with the first cart. The first cart moves down, then the second cart moves up - right into the first cart, colliding with it! (The location of the crash is marked with an <code>X</code>.) This ends the second and last tick.<p>
128 <p>Here is a longer example:</p>
129 <pre><code>/-&gt;-\
130 | | /----\
131 | /-+--+-\ |
132 | | | | v |
133 \-+-/ \-+--/
134 \------/
135
136 /--&gt;\
137 | | /----\
138 | /-+--+-\ |
139 | | | | | |
140 \-+-/ \-&gt;--/
141 \------/
142
143 /---v
144 | | /----\
145 | /-+--+-\ |
146 | | | | | |
147 \-+-/ \-+&gt;-/
148 \------/
149
150 /---\
151 | v /----\
152 | /-+--+-\ |
153 | | | | | |
154 \-+-/ \-+-&gt;/
155 \------/
156
157 /---\
158 | | /----\
159 | /-&gt;--+-\ |
160 | | | | | |
161 \-+-/ \-+--^
162 \------/
163
164 /---\
165 | | /----\
166 | /-+&gt;-+-\ |
167 | | | | | ^
168 \-+-/ \-+--/
169 \------/
170
171 /---\
172 | | /----\
173 | /-+-&gt;+-\ ^
174 | | | | | |
175 \-+-/ \-+--/
176 \------/
177
178 /---\
179 | | /----&lt;
180 | /-+--&gt;-\ |
181 | | | | | |
182 \-+-/ \-+--/
183 \------/
184
185 /---\
186 | | /---&lt;\
187 | /-+--+&gt;\ |
188 | | | | | |
189 \-+-/ \-+--/
190 \------/
191
192 /---\
193 | | /--&lt;-\
194 | /-+--+-v |
195 | | | | | |
196 \-+-/ \-+--/
197 \------/
198
199 /---\
200 | | /-&lt;--\
201 | /-+--+-\ |
202 | | | | v |
203 \-+-/ \-+--/
204 \------/
205
206 /---\
207 | | /&lt;---\
208 | /-+--+-\ |
209 | | | | | |
210 \-+-/ \-&lt;--/
211 \------/
212
213 /---\
214 | | v----\
215 | /-+--+-\ |
216 | | | | | |
217 \-+-/ \&lt;+--/
218 \------/
219
220 /---\
221 | | /----\
222 | /-+--v-\ |
223 | | | | | |
224 \-+-/ ^-+--/
225 \------/
226
227 /---\
228 | | /----\
229 | /-+--+-\ |
230 | | | X | |
231 \-+-/ \-+--/
232 \------/
233 </code></pre>
234 <p>After following their respective paths for a while, the carts eventually crash. To help prevent crashes, you'd like to know <em>the location of the first crash</em>. Locations are given in <code>X,Y</code> coordinates, where the furthest left column is <code>X=0</code> and the furthest top row is <code>Y=0</code>:</p>
235 <pre><code> 111
236 0123456789012
237 0/---\
238 1| | /----\
239 2| /-+--+-\ |
240 3| | | X | |
241 4\-+-/ \-+--/
242 5 \------/
243 </code></pre>
244 <p>In this example, the location of the first crash is <code><em>7,3</em></code>.</p>
245 </article>
246 <p>Your puzzle answer was <code>41,17</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>There isn't much you can do to prevent crashes in this ridiculous system. However, by predicting the crashes, the Elves know where to be in advance and <em>instantly remove the two crashing carts</em> the moment any crash occurs.</p>
247 <p>They can proceed like this for a while, but eventually, they're going to run out of carts. It could be useful to figure out where the last cart that <em>hasn't</em> crashed will end up.</p>
248 <p>For example:</p>
249 <pre><code>/&gt;-&lt;\
250 | |
251 | /&lt;+-\
252 | | | v
253 \&gt;+&lt;/ |
254 | ^
255 \&lt;-&gt;/
256
257 /---\
258 | |
259 | v-+-\
260 | | | |
261 \-+-/ |
262 | |
263 ^---^
264
265 /---\
266 | |
267 | /-+-\
268 | v | |
269 \-+-/ |
270 ^ ^
271 \---/
272
273 /---\
274 | |
275 | /-+-\
276 | | | |
277 \-+-/ <em>^</em>
278 | |
279 \---/
280 </code></pre>
281 <p>After four very expensive crashes, a tick ends with only one cart remaining; its final location is <code><em>6,4</em></code>.</p>
282 <p><em>What is the location of the last cart</em> at the end of the first tick where it is the only cart left?</p>
283 </article>
284 <p>Your puzzle answer was <code>134,117</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
285 <p>At this point, you should <a href="/2018">return to your advent calendar</a> and try another puzzle.</p>
286 <p>If you still want to see it, you can <a href="13/input" target="_blank">get your puzzle input</a>.</p>
287 <p>You can also <span class="share">[Share<span class="share-content">on
288 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Mine+Cart+Madness%22+%2D+Day+13+%2D+Advent+of+Code+2018&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2018%2Fday%2F13&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
289 <a href="http://www.reddit.com/submit?url=https%3A%2F%2Fadventofcode%2Ecom%2F2018%2Fday%2F13&amp;title=I%27ve+completed+%22Mine+Cart+Madness%22+%2D+Day+13+%2D+Advent+of+Code+2018" target="_blank">Reddit</a
290 ></span>]</span> this puzzle.</p>
291 </main>
292
293 <!-- ga -->
294 <script>
295 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
296 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
297 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
298 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
299 ga('create', 'UA-69522494-1', 'auto');
300 ga('send', 'pageview');
301 </script>
302 <!-- /ga -->
303 </body>
304 </html>