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"/>
16 Oh, hello! Funny seeing you here.
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.
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.
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
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!
35 If you'd like to hang out, I'm @ericwastl on Twitter.
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"> <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>
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&utm_medium=ch&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>
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>
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>
115 <p>Several
<em>carts
</em> are also on the tracks. Carts always face either up (
<code>^
</code>), down (
<code>v
</code>), left (
<code><</code>), or right (
<code>></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>
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>
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>
244 <p>In this example, the location of the first crash is
<code><em>7,
3</em></code>.
</p>
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>
249 <pre><code>/
>-
<\
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>
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&url=https%3A%2F%2Fadventofcode%2Ecom%2F2018%2Fday%2F13&related=ericwastl&hashtags=AdventOfCode" target=
"_blank">Twitter
</a>
289 <a href=
"http://www.reddit.com/submit?url=https%3A%2F%2Fadventofcode%2Ecom%2F2018%2Fday%2F13&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>
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');