Tidying
[advent-of-code-22.git] / problems / day22.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 22 - Advent of Code 2022</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?30"/>
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="/2022/about">[About]</a></li><li><a href="/2022/events">[Events]</a></li><li><a href="https://teespring.com/stores/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2022/settings">[Settings]</a></li><li><a href="/2022/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <a href="/2022/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">44*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">λy.</span><a href="/2022">2022</a><span class="title-event-wrap"></span></h1><nav><ul><li><a href="/2022">[Calendar]</a></li><li><a href="/2022/support">[AoC++]</a></li><li><a href="/2022/sponsors">[Sponsors]</a></li><li><a href="/2022/leaderboard">[Leaderboard]</a></li><li><a href="/2022/stats">[Stats]</a></li></ul></nav></div></header>
92
93 <div id="sidebar">
94 <div id="sponsor"><div class="quiet">Our <a href="/2022/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://www.sectorlabs.ro/jobs" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">SECTOR LABS</a> - &quot;Treating employees like adults since 2016&quot;</div></div>
95 </div><!--/sidebar-->
96
97 <main>
98 <article class="day-desc"><h2>--- Day 22: Monkey Map ---</h2><p>The monkeys take you on a surprisingly easy trail through the jungle. They're even going in roughly the right direction according to your handheld device's Grove Positioning System.</p>
99 <p>As you walk, the monkeys explain that the grove is protected by a <em>force field</em>. To pass through the force field, you have to enter a password; doing so involves tracing a specific <em>path</em> on a strangely-shaped board.</p>
100 <p>At least, you're pretty sure that's what you have to do; the elephants aren't exactly fluent in monkey.</p>
101 <p>The monkeys give you notes that they took when they last saw the password entered (your puzzle input).</p>
102 <p>For example:</p>
103 <pre><code> ...#
104 .#..
105 #...
106 ....
107 ...#.......#
108 ........#...
109 ..#....#....
110 ..........#.
111 ...#....
112 .....#..
113 .#......
114 ......#.
115
116 10R5L5R10L4R5L5
117 </code></pre>
118 <p>The first half of the monkeys' notes is a <em>map of the board</em>. It is comprised of a set of <em>open tiles</em> (on which you can move, drawn <code>.</code>) and <em>solid walls</em> (tiles which you cannot enter, drawn <code>#</code>).</p>
119 <p>The second half is a description of <em>the path you must follow</em>. It consists of alternating numbers and letters:</p>
120 <ul>
121 <li>A <em>number</em> indicates the <em>number of tiles to move</em> in the direction you are facing. If you run into a wall, you stop moving forward and continue with the next instruction.</li>
122 <li>A <em>letter</em> indicates whether to turn 90 degrees <em>clockwise</em> (<code>R</code>) or <em><span title="Or &quot;anticlockwise&quot;, if you're anti-counterclockwise.">counterclockwise</span></em> (<code>L</code>). Turning happens in-place; it does not change your current tile.</li>
123 </ul>
124 <p>So, a path like <code>10R5</code> means "go forward 10 tiles, then turn clockwise 90 degrees, then go forward 5 tiles".</p>
125 <p>You begin the path in the leftmost open tile of the top row of tiles. Initially, you are facing <em>to the right</em> (from the perspective of how the map is drawn).</p>
126 <p>If a movement instruction would take you off of the map, you <em>wrap around</em> to the other side of the board. In other words, if your next tile is off of the board, you should instead look in the direction opposite of your current facing as far as you can until you find the opposite edge of the board, then reappear there.</p>
127 <p>For example, if you are at <code>A</code> and facing to the right, the tile in front of you is marked <code>B</code>; if you are at <code>C</code> and facing down, the tile in front of you is marked <code>D</code>:</p>
128 <pre><code> ...#
129 .#..
130 #...
131 ....
132 ...#.<em>D</em>.....#
133 ........#...
134 <em>B</em>.#....#...<em>A</em>
135 .....<em>C</em>....#.
136 ...#....
137 .....#..
138 .#......
139 ......#.
140 </code></pre>
141 <p>It is possible for the next tile (after wrapping around) to be a <em>wall</em>; this still counts as there being a wall in front of you, and so movement stops before you actually wrap to the other side of the board.</p>
142 <p>By drawing the <em>last facing you had</em> with an arrow on each tile you visit, the full path taken by the above example looks like this:</p>
143 <pre><code> &gt;&gt;v#
144 .#v.
145 #.v.
146 ..v.
147 ...#...v..v#
148 &gt;&gt;&gt;v...<em>&gt;</em>#.&gt;&gt;
149 ..#v...#....
150 ...&gt;&gt;&gt;&gt;v..#.
151 ...#....
152 .....#..
153 .#......
154 ......#.
155 </code></pre>
156 <p>To finish providing the password to this strange input device, you need to determine numbers for your final <em>row</em>, <em>column</em>, and <em>facing</em> as your final position appears from the perspective of the original map. Rows start from <code>1</code> at the top and count downward; columns start from <code>1</code> at the left and count rightward. (In the above example, row 1, column 1 refers to the empty space with no tile on it in the top-left corner.) Facing is <code>0</code> for right (<code>&gt;</code>), <code>1</code> for down (<code>v</code>), <code>2</code> for left (<code>&lt;</code>), and <code>3</code> for up (<code>^</code>). The <em>final password</em> is the sum of 1000 times the row, 4 times the column, and the facing.</p>
157 <p>In the above example, the final row is <code>6</code>, the final column is <code>8</code>, and the final facing is <code>0</code>. So, the final password is 1000 * 6 + 4 * 8 + 0: <code><em>6032</em></code>.</p>
158 <p>Follow the path given in the monkeys' notes. <em>What is the final password?</em></p>
159 </article>
160 <p>Your puzzle answer was <code>26558</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>As you reach the force field, you think you hear some Elves in the distance. Perhaps they've already arrived?</p>
161 <p>You approach the strange <em>input device</em>, but it isn't quite what the monkeys drew in their notes. Instead, you are met with a large <em>cube</em>; each of its six faces is a square of 50x50 tiles.</p>
162 <p>To be fair, the monkeys' map <em>does</em> have six 50x50 regions on it. If you were to <em>carefully fold the map</em>, you should be able to shape it into a cube!</p>
163 <p>In the example above, the six (smaller, 4x4) faces of the cube are:</p>
164 <pre><code> 1111
165 1111
166 1111
167 1111
168 222233334444
169 222233334444
170 222233334444
171 222233334444
172 55556666
173 55556666
174 55556666
175 55556666
176 </code></pre>
177 <p>You still start in the same position and with the same facing as before, but the <em>wrapping</em> rules are different. Now, if you would walk off the board, you instead <em>proceed around the cube</em>. From the perspective of the map, this can look a little strange. In the above example, if you are at A and move to the right, you would arrive at B facing down; if you are at C and move down, you would arrive at D facing up:</p>
178 <pre><code> ...#
179 .#..
180 #...
181 ....
182 ...#.......#
183 ........#..<em>A</em>
184 ..#....#....
185 .<em>D</em>........#.
186 ...#..<em>B</em>.
187 .....#..
188 .#......
189 ..<em>C</em>...#.
190 </code></pre>
191 <p>Walls still block your path, even if they are on a different face of the cube. If you are at E facing up, your movement is blocked by the wall marked by the arrow:</p>
192 <pre><code> ...#
193 .#..
194 <em>--&gt;#</em>...
195 ....
196 ...#..<em>E</em>....#
197 ........#...
198 ..#....#....
199 ..........#.
200 ...#....
201 .....#..
202 .#......
203 ......#.
204 </code></pre>
205 <p>Using the same method of drawing the <em>last facing you had</em> with an arrow on each tile you visit, the full path taken by the above example now looks like this:</p>
206 <pre><code> &gt;&gt;v#
207 .#v.
208 #.v.
209 ..v.
210 ...#..<em>^</em>...v#
211 .&gt;&gt;&gt;&gt;&gt;^.#.&gt;&gt;
212 .^#....#....
213 .^........#.
214 ...#..v.
215 .....#v.
216 .#v&lt;&lt;&lt;&lt;.
217 ..v...#.
218 </code></pre>
219 <p>The final password is still calculated from your final position and facing from the perspective of the map. In this example, the final row is <code>5</code>, the final column is <code>7</code>, and the final facing is <code>3</code>, so the final password is 1000 * 5 + 4 * 7 + 3 = <code><em>5031</em></code>.</p>
220 <p>Fold the map into a cube, <em>then</em> follow the path given in the monkeys' notes. <em>What is the final password?</em></p>
221 </article>
222 <p>Your puzzle answer was <code>110400</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
223 <p>At this point, you should <a href="/2022">return to your Advent calendar</a> and try another puzzle.</p>
224 <p>If you still want to see it, you can <a href="22/input" target="_blank">get your puzzle input</a>.</p>
225 <p>You can also <span class="share">[Share<span class="share-content">on
226 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Monkey+Map%22+%2D+Day+22+%2D+Advent+of+Code+2022&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F22&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
227 <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+%22Monkey+Map%22+%2D+Day+22+%2D+Advent+of+Code+2022+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F22'}else{return false;}" target="_blank">Mastodon</a
228 ></span>]</span> this puzzle.</p>
229 </main>
230
231 <!-- ga -->
232 <script>
233 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
234 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
235 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
236 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
237 ga('create', 'UA-69522494-1', 'auto');
238 ga('set', 'anonymizeIp', true);
239 ga('send', 'pageview');
240 </script>
241 <!-- /ga -->
242 </body>
243 </html>