Tidying
[advent-of-code-22.git] / problems / day20.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 20 - 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">40*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;<span class="title-event-wrap">0.0.0.0:</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.accenture.com/us-en/industries/afs-index" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Accenture Federal Services</a> - Technology &amp; ingenuity moving missions forward – come solve problems with us. Hiring software engineers, developers, and more now. Refer someone to earn up to $20K.</div></div>
95 </div><!--/sidebar-->
96
97 <main>
98 <article class="day-desc"><h2>--- Day 20: Grove Positioning System ---</h2><p>It's finally time to meet back up with the Elves. When you try to contact them, however, you get no reply. Perhaps you're out of range?</p>
99 <p>You know they're headed to the grove where the <em class="star">star</em> fruit grows, so if you can figure out where that is, you should be able to meet back up with them.</p>
100 <p>Fortunately, your handheld device has a file (your puzzle input) that contains the grove's coordinates! Unfortunately, the file is <em>encrypted</em> - just in case the device were to fall into the wrong hands.</p>
101 <p>Maybe you can <span title="You once again make a mental note to remind the Elves later not to invent their own cryptographic functions.">decrypt</span> it?</p>
102 <p>When you were still back at the camp, you overheard some Elves talking about coordinate file encryption. The main operation involved in decrypting the file is called <em>mixing</em>.</p>
103 <p>The encrypted file is a list of numbers. To <em>mix</em> the file, move each number forward or backward in the file a number of positions equal to the value of the number being moved. The list is <em>circular</em>, so moving a number off one end of the list wraps back around to the other end as if the ends were connected.</p>
104 <p>For example, to move the <code>1</code> in a sequence like <code>4, 5, 6, <em>1</em>, 7, 8, 9</code>, the <code>1</code> moves one position forward: <code>4, 5, 6, 7, <em>1</em>, 8, 9</code>. To move the <code>-2</code> in a sequence like <code>4, <em>-2</em>, 5, 6, 7, 8, 9</code>, the <code>-2</code> moves two positions backward, wrapping around: <code>4, 5, 6, 7, 8, <em>-2</em>, 9</code>.</p>
105 <p>The numbers should be moved <em>in the order they originally appear</em> in the encrypted file. Numbers moving around during the mixing process do not change the order in which the numbers are moved.</p>
106 <p>Consider this encrypted file:</p>
107 <pre><code>1
108 2
109 -3
110 3
111 -2
112 0
113 4
114 </code></pre>
115 <p>Mixing this file proceeds as follows:</p>
116 <pre><code>Initial arrangement:
117 1, 2, -3, 3, -2, 0, 4
118
119 1 moves between 2 and -3:
120 2, 1, -3, 3, -2, 0, 4
121
122 2 moves between -3 and 3:
123 1, -3, 2, 3, -2, 0, 4
124
125 -3 moves between -2 and 0:
126 1, 2, 3, -2, -3, 0, 4
127
128 3 moves between 0 and 4:
129 1, 2, -2, -3, 0, 3, 4
130
131 -2 moves between 4 and 1:
132 1, 2, -3, 0, 3, 4, -2
133
134 0 does not move:
135 1, 2, -3, 0, 3, 4, -2
136
137 4 moves between -3 and 0:
138 1, 2, -3, 4, 0, 3, -2
139 </code></pre>
140 <p>Then, the grove coordinates can be found by looking at the 1000th, 2000th, and 3000th numbers after the value <code>0</code>, wrapping around the list as necessary. In the above example, the 1000th number after <code>0</code> is <code><em>4</em></code>, the 2000th is <code><em>-3</em></code>, and the 3000th is <code><em>2</em></code>; adding these together produces <code><em>3</em></code>.</p>
141 <p>Mix your encrypted file exactly once. <em>What is the sum of the three numbers that form the grove coordinates?</em></p>
142 </article>
143 <p>Your puzzle answer was <code>8721</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>The grove coordinate values seem nonsensical. While you ponder the mysteries of Elf encryption, you suddenly remember the rest of the decryption routine you overheard back at camp.</p>
144 <p>First, you need to apply the <em>decryption key</em>, <code>811589153</code>. Multiply each number by the decryption key before you begin; this will produce the actual list of numbers to mix.</p>
145 <p>Second, you need to mix the list of numbers <em>ten times</em>. The order in which the numbers are mixed does not change during mixing; the numbers are still moved in the order they appeared in the original, pre-mixed list. (So, if -3 appears fourth in the original list of numbers to mix, -3 will be the fourth number to move during each round of mixing.)</p>
146 <p>Using the same example as above:</p>
147 <pre><code>Initial arrangement:
148 811589153, 1623178306, -2434767459, 2434767459, -1623178306, 0, 3246356612
149
150 After 1 round of mixing:
151 0, -2434767459, 3246356612, -1623178306, 2434767459, 1623178306, 811589153
152
153 After 2 rounds of mixing:
154 0, 2434767459, 1623178306, 3246356612, -2434767459, -1623178306, 811589153
155
156 After 3 rounds of mixing:
157 0, 811589153, 2434767459, 3246356612, 1623178306, -1623178306, -2434767459
158
159 After 4 rounds of mixing:
160 0, 1623178306, -2434767459, 811589153, 2434767459, 3246356612, -1623178306
161
162 After 5 rounds of mixing:
163 0, 811589153, -1623178306, 1623178306, -2434767459, 3246356612, 2434767459
164
165 After 6 rounds of mixing:
166 0, 811589153, -1623178306, 3246356612, -2434767459, 1623178306, 2434767459
167
168 After 7 rounds of mixing:
169 0, -2434767459, 2434767459, 1623178306, -1623178306, 811589153, 3246356612
170
171 After 8 rounds of mixing:
172 0, 1623178306, 3246356612, 811589153, -2434767459, 2434767459, -1623178306
173
174 After 9 rounds of mixing:
175 0, 811589153, 1623178306, -2434767459, 3246356612, 2434767459, -1623178306
176
177 After 10 rounds of mixing:
178 0, -2434767459, 1623178306, 3246356612, -1623178306, 2434767459, 811589153
179 </code></pre>
180 <p>The grove coordinates can still be found in the same way. Here, the 1000th number after <code>0</code> is <code><em>811589153</em></code>, the 2000th is <code><em>2434767459</em></code>, and the 3000th is <code><em>-1623178306</em></code>; adding these together produces <code><em>1623178306</em></code>.</p>
181 <p>Apply the decryption key and mix your encrypted file ten times. <em>What is the sum of the three numbers that form the grove coordinates?</em></p>
182 </article>
183 <p>Your puzzle answer was <code>831878881825</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
184 <p>At this point, you should <a href="/2022">return to your Advent calendar</a> and try another puzzle.</p>
185 <p>If you still want to see it, you can <a href="20/input" target="_blank">get your puzzle input</a>.</p>
186 <p>You can also <span class="share">[Share<span class="share-content">on
187 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Grove+Positioning+System%22+%2D+Day+20+%2D+Advent+of+Code+2022&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F20&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
188 <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+%22Grove+Positioning+System%22+%2D+Day+20+%2D+Advent+of+Code+2022+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F20'}else{return false;}" target="_blank">Mastodon</a
189 ></span>]</span> this puzzle.</p>
190 </main>
191
192 <!-- ga -->
193 <script>
194 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
195 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
196 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
197 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
198 ga('create', 'UA-69522494-1', 'auto');
199 ga('set', 'anonymizeIp', true);
200 ga('send', 'pageview');
201 </script>
202 <!-- /ga -->
203 </body>
204 </html>