Done day 16
[advent-of-code-18.git] / problems / day16.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 16 - 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"/>
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 Google, and I can only take
23 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, ads, social media),
27 I built the whole thing myself, including the design, animations, prose, and
28 all of the puzzles.
29
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!
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="/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">32*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">0xffff&amp;</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>
91
92 <div id="sidebar">
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://formlabs.com/jobs/" target="_blank" onclick="if(ga)ga('send','event','sponsor','click',this.href);" rel="noopener">Formlabs</a> - 3D printing with lasers. Software, hardware, and more. Pew pew!</div></div>
94 </div><!--/sidebar-->
95
96 <main>
97 <article class="day-desc"><h2>--- Day 16: Chronal Classification ---</h2><p>As you see the Elves defend their hot chocolate successfully, you go back to falling through time. This is going to become a problem.</p>
98 <p>If you're ever going to return to your own time, you need to understand how this device on your wrist works. You have a little while before you reach your next destination, and with a bit of trial and error, you manage to pull up a programming manual on the device's tiny screen.</p>
99 <p>According to the manual, the device has four <a href="https://en.wikipedia.org/wiki/Hardware_register">registers</a> (numbered <code>0</code> through <code>3</code>) that can be manipulated by <a href="https://en.wikipedia.org/wiki/Instruction_set_architecture#Instructions">instructions</a> containing one of 16 opcodes. The registers start with the value <code>0</code>.</p>
100 <p>Every instruction consists of four values: an <em>opcode</em>, two <em>inputs</em> (named <code>A</code> and <code>B</code>), and an <em>output</em> (named <code>C</code>), in that order. The opcode specifies the behavior of the instruction and how the inputs are interpreted. The output, <code>C</code>, is always treated as a register.</p>
101 <p>In the opcode descriptions below, if something says "<em>value <code>A</code></em>", it means to take the number given as <code>A</code> <em>literally</em>. (This is also called an "immediate" value.) If something says "<em>register <code>A</code></em>", it means to use the number given as <code>A</code> to read from (or write to) the <em>register with that number</em>. So, if the opcode <code>addi</code> adds register <code>A</code> and value <code>B</code>, storing the result in register <code>C</code>, and the instruction <code>addi 0 7 3</code> is encountered, it would add <code>7</code> to the value contained by register <code>0</code> and store the sum in register <code>3</code>, never modifying registers <code>0</code>, <code>1</code>, or <code>2</code> in the process.</p>
102 <p>Many opcodes are similar except for how they interpret their arguments. The opcodes fall into seven general categories:</p>
103 <p>Addition:</p>
104 <ul>
105 <li><code>addr</code> (add register) stores into register <code>C</code> the result of adding register <code>A</code> and register <code>B</code>.</li>
106 <li><code>addi</code> (add immediate) stores into register <code>C</code> the result of adding register <code>A</code> and value <code>B</code>.</li>
107 </ul>
108 <p>Multiplication:</p>
109 <ul>
110 <li><code>mulr</code> (multiply register) stores into register <code>C</code> the result of multiplying register <code>A</code> and register <code>B</code>.</li>
111 <li><code>muli</code> (multiply immediate) stores into register <code>C</code> the result of multiplying register <code>A</code> and value <code>B</code>.</li>
112 </ul>
113 <p><a href="https://en.wikipedia.org/wiki/Bitwise_AND">Bitwise AND</a>:</p>
114 <ul>
115 <li><code>banr</code> (bitwise AND register) stores into register <code>C</code> the result of the bitwise AND of register <code>A</code> and register <code>B</code>.</li>
116 <li><code>bani</code> (bitwise AND immediate) stores into register <code>C</code> the result of the bitwise AND of register <code>A</code> and value <code>B</code>.</li>
117 </ul>
118 <p><a href="https://en.wikipedia.org/wiki/Bitwise_OR">Bitwise OR</a>:</p>
119 <ul>
120 <li><code>borr</code> (bitwise OR register) stores into register <code>C</code> the result of the bitwise OR of register <code>A</code> and register <code>B</code>.</li>
121 <li><code>bori</code> (bitwise OR immediate) stores into register <code>C</code> the result of the bitwise OR of register <code>A</code> and value <code>B</code>.</li>
122 </ul>
123 <p>Assignment:</p>
124 <ul>
125 <li><code>setr</code> (set register) copies the contents of register <code>A</code> into register <code>C</code>. (Input <code>B</code> is ignored.)</li>
126 <li><code>seti</code> (set immediate) stores value <code>A</code> into register <code>C</code>. (Input <code>B</code> is ignored.)</li>
127 </ul>
128 <p>Greater-than testing:</p>
129 <ul>
130 <li><code>gtir</code> (greater-than immediate/register) sets register <code>C</code> to <code>1</code> if value <code>A</code> is greater than register <code>B</code>. Otherwise, register <code>C</code> is set to <code>0</code>.</li>
131 <li><code>gtri</code> (greater-than register/immediate) sets register <code>C</code> to <code>1</code> if register <code>A</code> is greater than value <code>B</code>. Otherwise, register <code>C</code> is set to <code>0</code>.</li>
132 <li><code>gtrr</code> (greater-than register/register) sets register <code>C</code> to <code>1</code> if register <code>A</code> is greater than register <code>B</code>. Otherwise, register <code>C</code> is set to <code>0</code>.</li>
133 </ul>
134 <p>Equality testing:</p>
135 <ul>
136 <li><code>eqir</code> (equal immediate/register) sets register <code>C</code> to <code>1</code> if value <code>A</code> is equal to register <code>B</code>. Otherwise, register <code>C</code> is set to <code>0</code>.</li>
137 <li><code>eqri</code> (equal register/immediate) sets register <code>C</code> to <code>1</code> if register <code>A</code> is equal to value <code>B</code>. Otherwise, register <code>C</code> is set to <code>0</code>.</li>
138 <li><code>eqrr</code> (equal register/register) sets register <code>C</code> to <code>1</code> if register <code>A</code> is equal to register <code>B</code>. Otherwise, register <code>C</code> is set to <code>0</code>.</li>
139 </ul>
140 <p>Unfortunately, while the manual gives the <em>name</em> of each opcode, it doesn't seem to indicate the <em>number</em>. However, you can monitor the CPU to see the contents of the registers before and after instructions are executed to try to work them out. Each opcode has a number from <code>0</code> through <code>15</code>, but the manual doesn't say which is which. For example, suppose you capture the following sample:</p>
141 <pre><code>Before: [3, 2, 1, 1]
142 9 2 1 2
143 After: [3, 2, 2, 1]
144 </code></pre>
145 <p>This sample shows the effect of the instruction <code>9 2 1 2</code> on the registers. Before the instruction is executed, register <code>0</code> has value <code>3</code>, register <code>1</code> has value <code>2</code>, and registers <code>2</code> and <code>3</code> have value <code>1</code>. After the instruction is executed, register <code>2</code>'s value becomes <code>2</code>.</p>
146 <p>The instruction itself, <code>9 2 1 2</code>, means that opcode <code>9</code> was executed with <code>A=2</code>, <code>B=1</code>, and <code>C=2</code>. Opcode <code>9</code> could be any of the 16 opcodes listed above, but only three of them behave in a way that would cause the result shown in the sample:</p>
147 <ul>
148 <li>Opcode <code>9</code> could be <code>mulr</code>: register <code>2</code> (which has a value of <code>1</code>) times register <code>1</code> (which has a value of <code>2</code>) produces <code>2</code>, which matches the value stored in the output register, register <code>2</code>.</li>
149 <li>Opcode <code>9</code> could be <code>addi</code>: register <code>2</code> (which has a value of <code>1</code>) plus value <code>1</code> produces <code>2</code>, which matches the value stored in the output register, register <code>2</code>.</li>
150 <li>Opcode <code>9</code> could be <code>seti</code>: value <code>2</code> matches the value stored in the output register, register <code>2</code>; the number given for <code>B</code> is irrelevant.</li>
151 </ul>
152 <p>None of the other opcodes produce the result captured in the sample. Because of this, the sample above <em>behaves like three opcodes</em>.</p>
153 <p>You collect many of these samples (the first section of your puzzle input). The manual also includes a small test program (the second section of your puzzle input) - you can <em>ignore it for now</em>.</p>
154 <p>Ignoring the opcode numbers, <em>how many samples in your puzzle input behave like three or more opcodes?</em></p>
155 </article>
156 <p>Your puzzle answer was <code>580</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>Using the samples you collected, <span title="This is one of my favorite puzzles.">work out the number of each opcode</span> and execute the test program (the second section of your puzzle input).</p>
157 <p><em>What value is contained in register <code>0</code> after executing the test program?</em></p>
158 </article>
159 <p>Your puzzle answer was <code>537</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
160 <p>At this point, you should <a href="/2018">return to your advent calendar</a> and try another puzzle.</p>
161 <p>If you still want to see it, you can <a href="16/input" target="_blank">get your puzzle input</a>.</p>
162 <p>You can also <span class="share">[Share<span class="share-content">on
163 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Chronal+Classification%22+%2D+Day+16+%2D+Advent+of+Code+2018&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2018%2Fday%2F16&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
164 <a href="http://www.reddit.com/submit?url=https%3A%2F%2Fadventofcode%2Ecom%2F2018%2Fday%2F16&amp;title=I%27ve+completed+%22Chronal+Classification%22+%2D+Day+16+%2D+Advent+of+Code+2018" target="_blank">Reddit</a
165 ></span>]</span> this puzzle.</p>
166 </main>
167
168 <!-- ga -->
169 <script>
170 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
171 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
172 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
173 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
174 ga('create', 'UA-69522494-1', 'auto');
175 ga('send', 'pageview');
176 </script>
177 <!-- /ga -->
178 </body>
179 </html>