Done day 16
[advent-of-code-18.git] / problems / day16.html
diff --git a/problems/day16.html b/problems/day16.html
new file mode 100644 (file)
index 0000000..8b5ecf5
--- /dev/null
@@ -0,0 +1,179 @@
+<!DOCTYPE html>
+<html lang="en-us">
+<head>
+<meta charset="utf-8"/>
+<title>Day 16 - Advent of Code 2018</title>
+<!--[if lt IE 9]><script src="/static/html5.js"></script><![endif]-->
+<link href='//fonts.googleapis.com/css?family=Source+Code+Pro:300&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
+<link rel="stylesheet" type="text/css" href="/static/style.css?18"/>
+<link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?0" title="High Contrast"/>
+<link rel="shortcut icon" href="/favicon.png"/>
+</head><!--
+
+
+
+
+Oh, hello!  Funny seeing you here.
+
+I appreciate your enthusiasm, but you aren't going to find much down here.
+There certainly aren't clues to any of the puzzles.  The best surprises don't
+even appear in the source until you unlock them for real.
+
+Please be careful with automated requests; I'm not Google, and I can only take
+so much traffic.  Please be considerate so that everyone gets to play.
+
+If you're curious about how Advent of Code works, it's running on some custom
+Perl code. Other than a few integrations (auth, analytics, ads, social media),
+I built the whole thing myself, including the design, animations, prose, and
+all of the puzzles.
+
+The puzzles are most of the work; the easiest ones take 3-4 hours each, but the
+harder ones take 6-8 hours, and a few even longer than that. A lot of effort
+went into building this thing - I hope you're enjoying playing it as much as I
+enjoyed making it for you!
+
+If you'd like to hang out, I'm @ericwastl on Twitter.
+
+- Eric Wastl
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+-->
+<body>
+<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>
+
+<div id="sidebar">
+<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>
+</div><!--/sidebar-->
+
+<main>
+<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>
+<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>
+<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>
+<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>
+<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>
+<p>Many opcodes are similar except for how they interpret their arguments. The opcodes fall into seven general categories:</p>
+<p>Addition:</p>
+<ul>
+<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>
+<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>
+</ul>
+<p>Multiplication:</p>
+<ul>
+<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>
+<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>
+</ul>
+<p><a href="https://en.wikipedia.org/wiki/Bitwise_AND">Bitwise AND</a>:</p>
+<ul>
+<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>
+<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>
+</ul>
+<p><a href="https://en.wikipedia.org/wiki/Bitwise_OR">Bitwise OR</a>:</p>
+<ul>
+<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>
+<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>
+</ul>
+<p>Assignment:</p>
+<ul>
+<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>
+<li><code>seti</code> (set immediate) stores value <code>A</code> into register <code>C</code>. (Input <code>B</code> is ignored.)</li>
+</ul>
+<p>Greater-than testing:</p>
+<ul>
+<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>
+<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>
+<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>
+</ul>
+<p>Equality testing:</p>
+<ul>
+<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>
+<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>
+<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>
+</ul>
+<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>
+<pre><code>Before: [3, 2, 1, 1]
+9 2 1 2
+After:  [3, 2, 2, 1]
+</code></pre>
+<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>
+<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>
+<ul>
+<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>
+<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>
+<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>
+</ul>
+<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>
+<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>
+<p>Ignoring the opcode numbers, <em>how many samples in your puzzle input behave like three or more opcodes?</em></p>
+</article>
+<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>
+<p><em>What value is contained in register <code>0</code> after executing the test program?</em></p>
+</article>
+<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>
+<p>At this point, you should <a href="/2018">return to your advent calendar</a> and try another puzzle.</p>
+<p>If you still want to see it, you can <a href="16/input" target="_blank">get your puzzle input</a>.</p>
+<p>You can also <span class="share">[Share<span class="share-content">on
+  <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>
+  <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
+></span>]</span> this puzzle.</p>
+</main>
+
+<!-- ga -->
+<script>
+(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
+(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
+m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
+})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
+ga('create', 'UA-69522494-1', 'auto');
+ga('send', 'pageview');
+</script>
+<!-- /ga -->
+</body>
+</html>
\ No newline at end of file