Done day 22
[advent-of-code-21.git] / problems / day02.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 2 - Advent of Code 2021</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?26"/>
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 a massive company, and I can
23 only take 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, social media), I
27 built the whole thing myself, including the design, animations, prose, and all
28 of the puzzles.
29
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!
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="/2021/about">[About]</a></li><li><a href="/2021/events">[Events]</a></li><li><a href="https://teespring.com/stores/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2021/settings">[Settings]</a></li><li><a href="/2021/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <a href="/2021/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">4*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">int y=</span><a href="/2021">2021</a><span class="title-event-wrap">;</span></h1><nav><ul><li><a href="/2021">[Calendar]</a></li><li><a href="/2021/support">[AoC++]</a></li><li><a href="/2021/sponsors">[Sponsors]</a></li><li><a href="/2021/leaderboard">[Leaderboard]</a></li><li><a href="/2021/stats">[Stats]</a></li></ul></nav></div></header>
91
92 <div id="sidebar">
93 <div id="sponsor"><div class="quiet">Our <a href="/2021/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://www.ing.jobs/Global/Careers/expertise/Tech.htm" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">ING</a> - At ING, you develop software and yourself</div></div>
94 </div><!--/sidebar-->
95
96 <main>
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 2: Dive! ---</h2><p>Now, you need to figure out how to <span title="Tank, I need a pilot program for a B212 helicopter.">pilot this thing</span>.</p>
99 <p>It seems like the submarine can take a series of commands like <code>forward 1</code>, <code>down 2</code>, or <code>up 3</code>:</p>
100 <ul>
101 <li><code>forward X</code> increases the horizontal position by <code>X</code> units.</li>
102 <li><code>down X</code> <em>increases</em> the depth by <code>X</code> units.</li>
103 <li><code>up X</code> <em>decreases</em> the depth by <code>X</code> units.</li>
104 </ul>
105 <p>Note that since you're on a submarine, <code>down</code> and <code>up</code> affect your <em>depth</em>, and so they have the opposite result of what you might expect.</p>
106 <p>The submarine seems to already have a planned course (your puzzle input). You should probably figure out where it's going. For example:</p>
107 <pre><code>forward 5
108 down 5
109 forward 8
110 up 3
111 down 8
112 forward 2
113 </code></pre>
114 <p>Your horizontal position and depth both start at <code>0</code>. The steps above would then modify them as follows:</p>
115 <ul>
116 <li><code>forward 5</code> adds <code>5</code> to your horizontal position, a total of <code>5</code>.</li>
117 <li><code>down 5</code> adds <code>5</code> to your depth, resulting in a value of <code>5</code>.</li>
118 <li><code>forward 8</code> adds <code>8</code> to your horizontal position, a total of <code>13</code>.</li>
119 <li><code>up 3</code> decreases your depth by <code>3</code>, resulting in a value of <code>2</code>.</li>
120 <li><code>down 8</code> adds <code>8</code> to your depth, resulting in a value of <code>10</code>.</li>
121 <li><code>forward 2</code> adds <code>2</code> to your horizontal position, a total of <code>15</code>.</li>
122 </ul>
123 <p>After following these instructions, you would have a horizontal position of <code>15</code> and a depth of <code>10</code>. (Multiplying these together produces <code><em>150</em></code>.)</p>
124 <p>Calculate the horizontal position and depth you would have after following the planned course. <em>What do you get if you multiply your final horizontal position by your final depth?</em></p>
125 </article>
126 <p>Your puzzle answer was <code>2039912</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>Based on your calculations, the planned course doesn't seem to make any sense. You find the submarine manual and discover that the process is actually slightly more complicated.</p>
127 <p>In addition to horizontal position and depth, you'll also need to track a third value, <em>aim</em>, which also starts at <code>0</code>. The commands also mean something entirely different than you first thought:</p>
128 <ul>
129 <li><code>down X</code> <em>increases</em> your aim by <code>X</code> units.</li>
130 <li><code>up X</code> <em>decreases</em> your aim by <code>X</code> units.</li>
131 <li><code>forward X</code> does two things:<ul>
132 <li>It increases your horizontal position by <code>X</code> units.</li>
133 <li>It increases your depth by your aim <em>multiplied by</em> <code>X</code>.</li>
134 </ul></li>
135 </ul>
136 <p>Again note that since you're on a submarine, <code>down</code> and <code>up</code> do the opposite of what you might expect: "down" means aiming in the positive direction.</p>
137 <p>Now, the above example does something different:</p>
138 <ul>
139 <li><code>forward 5</code> adds <code>5</code> to your horizontal position, a total of <code>5</code>. Because your aim is <code>0</code>, your depth does not change.</li>
140 <li><code>down 5</code> adds <code>5</code> to your aim, resulting in a value of <code>5</code>.</li>
141 <li><code>forward 8</code> adds <code>8</code> to your horizontal position, a total of <code>13</code>. Because your aim is <code>5</code>, your depth increases by <code>8*5=40</code>.</li>
142 <li><code>up 3</code> decreases your aim by <code>3</code>, resulting in a value of <code>2</code>.</li>
143 <li><code>down 8</code> adds <code>8</code> to your aim, resulting in a value of <code>10</code>.</li>
144 <li><code>forward 2</code> adds <code>2</code> to your horizontal position, a total of <code>15</code>. Because your aim is <code>10</code>, your depth increases by <code>2*10=20</code> to a total of <code>60</code>.</li>
145 </ul>
146 <p>After following these new instructions, you would have a horizontal position of <code>15</code> and a depth of <code>60</code>. (Multiplying these produces <code><em>900</em></code>.)</p>
147 <p>Using this new interpretation of the commands, calculate the horizontal position and depth you would have after following the planned course. <em>What do you get if you multiply your final horizontal position by your final depth?</em></p>
148 </article>
149 <p>Your puzzle answer was <code>1942068080</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
150 <p>At this point, you should <a href="/2021">return to your Advent calendar</a> and try another puzzle.</p>
151 <p>If you still want to see it, you can <a href="2/input" target="_blank">get your puzzle input</a>.</p>
152 <p>You can also <span class="share">[Share<span class="share-content">on
153 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Dive%21%22+%2D+Day+2+%2D+Advent+of+Code+2021&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2021%2Fday%2F2&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
154 <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+%22Dive%21%22+%2D+Day+2+%2D+Advent+of+Code+2021+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2021%2Fday%2F2'}else{return false;}" target="_blank">Mastodon</a
155 ></span>]</span> this puzzle.</p>
156 </main>
157
158 <!-- ga -->
159 <script>
160 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
161 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
162 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
163 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
164 ga('create', 'UA-69522494-1', 'auto');
165 ga('set', 'anonymizeIp', true);
166 ga('send', 'pageview');
167 </script>
168 <!-- /ga -->
169 </body>
170 </html>