4 <meta charset=
"utf-8"/>
5 <title>Day
12 - Advent of Code
2020</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?25"/>
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 a massive company, and I can
23 only take 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, social media), I
27 built the whole thing myself, including the design, animations, prose, and all
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!
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=
"/2020/about">[About]
</a></li><li><a href=
"/2020/events">[Events]
</a></li><li><a href=
"https://teespring.com/stores/advent-of-code" target=
"_blank">[Shop]
</a></li><li><a href=
"/2020/settings">[Settings]
</a></li><li><a href=
"/2020/auth/logout">[Log Out]
</a></li></ul></nav><div class=
"user">Neil Smith
<a href=
"/2020/support" class=
"supporter-badge" title=
"Advent of Code Supporter">(AoC++)
</a> <span class=
"star-count">24*
</span></div></div><div><h1 class=
"title-event"> <span class=
"title-event-wrap">/*
</span><a href=
"/2020">2020</a><span class=
"title-event-wrap">*/
</span></h1><nav><ul><li><a href=
"/2020">[Calendar]
</a></li><li><a href=
"/2020/support">[AoC++]
</a></li><li><a href=
"/2020/sponsors">[Sponsors]
</a></li><li><a href=
"/2020/leaderboard">[Leaderboard]
</a></li><li><a href=
"/2020/stats">[Stats]
</a></li></ul></nav></div></header>
93 <div id=
"sponsor"><div class=
"quiet">Our
<a href=
"/2020/sponsors">sponsors
</a> help make Advent of Code possible:
</div><div class=
"sponsor"><a href=
"https://www.bjss.com/joinus/" target=
"_blank" onclick=
"if(ga)ga('send','event','sponsor','sidebar',this.href);" rel=
"noopener">BJSS
</a> - Good luck all. Hoping to see some BJSSers top of the leaderboard!
</div></div>
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
12: Rain Risk ---
</h2><p>Your ferry made decent progress toward the island, but the storm came in
<span title=
"At least it wasn't a Category Six!">faster than anyone expected
</span>. The ferry needs to take
<em>evasive actions
</em>!
</p>
99 <p>Unfortunately, the ship's navigation computer seems to be malfunctioning; rather than giving a route directly to safety, it produced extremely circuitous instructions. When the captain uses the
<a href=
"https://en.wikipedia.org/wiki/Public_address_system" target=
"_blank">PA system
</a> to ask if anyone can help, you quickly volunteer.
</p>
100 <p>The navigation instructions (your puzzle input) consists of a sequence of single-character
<em>actions
</em> paired with integer input
<em>values
</em>. After staring at them for a few minutes, you work out what they probably mean:
</p>
102 <li>Action
<em><code>N
</code></em> means to move
<em>north
</em> by the given value.
</li>
103 <li>Action
<em><code>S
</code></em> means to move
<em>south
</em> by the given value.
</li>
104 <li>Action
<em><code>E
</code></em> means to move
<em>east
</em> by the given value.
</li>
105 <li>Action
<em><code>W
</code></em> means to move
<em>west
</em> by the given value.
</li>
106 <li>Action
<em><code>L
</code></em> means to turn
<em>left
</em> the given number of degrees.
</li>
107 <li>Action
<em><code>R
</code></em> means to turn
<em>right
</em> the given number of degrees.
</li>
108 <li>Action
<em><code>F
</code></em> means to move
<em>forward
</em> by the given value in the direction the ship is currently facing.
</li>
110 <p>The ship starts by facing
<em>east
</em>. Only the
<code>L
</code> and
<code>R
</code> actions change the direction the ship is facing. (That is, if the ship is facing east and the next instruction is
<code>N10
</code>, the ship would move north
10 units, but would still move east if the following action were
<code>F
</code>.)
</p>
118 <p>These instructions would be handled as follows:
</p>
120 <li><code>F10
</code> would move the ship
10 units east (because the ship starts by facing east) to
<em>east
10, north
0</em>.
</li>
121 <li><code>N3
</code> would move the ship
3 units north to
<em>east
10, north
3</em>.
</li>
122 <li><code>F7
</code> would move the ship another
7 units east (because the ship is still facing east) to
<em>east
17, north
3</em>.
</li>
123 <li><code>R90
</code> would cause the ship to turn right by
90 degrees and face
<em>south
</em>; it remains at
<em>east
17, north
3</em>.
</li>
124 <li><code>F11
</code> would move the ship
11 units south to
<em>east
17, south
8</em>.
</li>
126 <p>At the end of these instructions, the ship's
<a href=
"https://en.wikipedia.org/wiki/Manhattan_distance" target=
"_blank">Manhattan distance
</a> (sum of the absolute values of its east/west position and its north/south position) from its starting position is
<code>17 +
8</code> =
<em><code>25</code></em>.
</p>
127 <p>Figure out where the navigation instructions lead.
<em>What is the Manhattan distance between that location and the ship's starting position?
</em></p>
129 <p>Your puzzle answer was
<code>1106</code>.
</p><article class=
"day-desc"><h2 id=
"part2">--- Part Two ---
</h2><p>Before you can give the destination to the captain, you realize that the actual action meanings were printed on the back of the instructions the whole time.
</p>
130 <p>Almost all of the actions indicate how to move a
<em>waypoint
</em> which is relative to the ship's position:
</p>
132 <li>Action
<em><code>N
</code></em> means to move the waypoint
<em>north
</em> by the given value.
</li>
133 <li>Action
<em><code>S
</code></em> means to move the waypoint
<em>south
</em> by the given value.
</li>
134 <li>Action
<em><code>E
</code></em> means to move the waypoint
<em>east
</em> by the given value.
</li>
135 <li>Action
<em><code>W
</code></em> means to move the waypoint
<em>west
</em> by the given value.
</li>
136 <li>Action
<em><code>L
</code></em> means to rotate the waypoint around the ship
<em>left
</em> (
<em>counter-clockwise
</em>) the given number of degrees.
</li>
137 <li>Action
<em><code>R
</code></em> means to rotate the waypoint around the ship
<em>right
</em> (
<em>clockwise
</em>) the given number of degrees.
</li>
138 <li>Action
<em><code>F
</code></em> means to move
<em>forward
</em> to the waypoint a number of times equal to the given value.
</li>
140 <p>The waypoint starts
<em>10 units east and
1 unit north
</em> relative to the ship. The waypoint is relative to the ship; that is, if the ship moves, the waypoint moves with it.
</p>
141 <p>For example, using the same instructions as above:
</p>
143 <li><code>F10
</code> moves the ship to the waypoint
10 times (a total of
<em>100 units east and
10 units north
</em>), leaving the ship at
<em>east
100, north
10</em>. The waypoint stays
10 units east and
1 unit north of the ship.
</li>
144 <li><code>N3
</code> moves the waypoint
3 units north to
<em>10 units east and
4 units north of the ship
</em>. The ship remains at
<em>east
100, north
10</em>.
</li>
145 <li><code>F7
</code> moves the ship to the waypoint
7 times (a total of
<em>70 units east and
28 units north
</em>), leaving the ship at
<em>east
170, north
38</em>. The waypoint stays
10 units east and
4 units north of the ship.
</li>
146 <li><code>R90
</code> rotates the waypoint around the ship clockwise
90 degrees, moving it to
<em>4 units east and
10 units south of the ship
</em>. The ship remains at
<em>east
170, north
38</em>.
</li>
147 <li><code>F11
</code> moves the ship to the waypoint
11 times (a total of
<em>44 units east and
110 units south
</em>), leaving the ship at
<em>east
214, south
72</em>. The waypoint stays
4 units east and
10 units south of the ship.
</li>
149 <p>After these operations, the ship's Manhattan distance from its starting position is
<code>214 +
72</code> =
<em><code>286</code></em>.
</p>
150 <p>Figure out where the navigation instructions actually lead.
<em>What is the Manhattan distance between that location and the ship's starting position?
</em></p>
152 <p>Your puzzle answer was
<code>107281</code>.
</p><p class=
"day-success">Both parts of this puzzle are complete! They provide two gold stars: **
</p>
153 <p>At this point, you should
<a href=
"/2020">return to your Advent calendar
</a> and try another puzzle.
</p>
154 <p>If you still want to see it, you can
<a href=
"12/input" target=
"_blank">get your puzzle input
</a>.
</p>
155 <p>You can also
<span class=
"share">[Share
<span class=
"share-content">on
156 <a href=
"https://twitter.com/intent/tweet?text=I%27ve+completed+%22Rain+Risk%22+%2D+Day+12+%2D+Advent+of+Code+2020&url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F12&related=ericwastl&hashtags=AdventOfCode" target=
"_blank">Twitter
</a>
157 <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+%22Rain+Risk%22+%2D+Day+12+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F12'}else{return false;}" target=
"_blank">Mastodon
</a
158 ></span>]
</span> this puzzle.
</p>
163 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
164 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=
1*new Date();a=s.createElement(o),
165 m=s.getElementsByTagName(o)[
0];a.async=
1;a.src=g;m.parentNode.insertBefore(a,m)
166 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
167 ga('create', 'UA-
69522494-
1', 'auto');
168 ga('set', 'anonymizeIp', true);
169 ga('send', 'pageview');