148 lines
8.3 KiB
HTML
148 lines
8.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en-us">
|
|
<head>
|
|
<meta charset="utf-8"/>
|
|
<title>Day 14 - Advent of Code 2020</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?25"/>
|
|
<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 a massive company, 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, 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; preparing a new calendar and a new set of
|
|
puzzles each year takes all of my free time for 4-5 months. 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="/2020/about">[About]</a></li><li><a href="/2020/events">[Events]</a></li><li><a href="https://teespring.com/stores/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2020/settings">[Settings]</a></li><li><a href="/2020/auth/logout">[Log Out]</a></li></ul></nav><div class="user">m42e <a href="/2020/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">26*</span></div></div><div><h1 class="title-event"> <span class="title-event-wrap">/*</span><a href="/2020">2020</a><span class="title-event-wrap">*/</span></h1><nav><ul><li><a href="/2020">[Calendar]</a></li><li><a href="/2020/support">[AoC++]</a></li><li><a href="/2020/sponsors">[Sponsors]</a></li><li><a href="/2020/leaderboard">[Leaderboard]</a></li><li><a href="/2020/stats">[Stats]</a></li></ul></nav></div></header>
|
|
|
|
<div id="sidebar">
|
|
<div id="sponsor"><div class="quiet">Our <a href="/2020/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://github.com/" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">GitHub</a> - We're hiring engineers to make GitHub fast. Interested? Email fast@github.com with details of exceptional performance work you've done in the past.</div></div>
|
|
</div><!--/sidebar-->
|
|
|
|
<main>
|
|
<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>
|
|
<article class="day-desc"><h2>--- Day 14: Docking Data ---</h2><p>As your ferry approaches the sea port, the captain asks for your help again. The computer system that runs this port isn't compatible with the docking program on the ferry, so the docking parameters aren't being correctly initialized in the docking program's memory.</p>
|
|
<p>After a brief inspection, you discover that the sea port's computer system uses a strange <a href="https://en.wikipedia.org/wiki/Mask_(computing)" target="_blank">bitmask</a> system in its initialization program. Although you don't have the correct decoder chip handy, you can emulate it in software!</p>
|
|
<p>The initialization program (your puzzle input) can either update the bitmask or write a value to memory. Values and memory addresses are both 36-bit unsigned integers. For example, ignoring bitmasks for a moment, a line like <code>mem[8] = 11</code> would write the value <code>11</code> to memory address <code>8</code>.</p>
|
|
<p>The bitmask is always given as a string of 36 bits, written with the most significant bit (representing <code>2^35</code>) on the left and the least significant bit (<code>2^0</code>, that is, the <code>1</code>s bit) on the right. The current bitmask is applied to values immediately before they are written to memory: a <code>0</code> or <code>1</code> overwrites the corresponding bit in the value, while an <code>X</code> leaves the bit in the value unchanged.</p>
|
|
<p>For example, consider the following program:</p>
|
|
<pre><code>mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
|
|
mem[8] = 11
|
|
mem[7] = 101
|
|
mem[8] = 0
|
|
</code></pre>
|
|
<p>This program starts by specifying a bitmask (<code>mask = ....</code>). The mask it specifies will overwrite two bits in every written value: the <code>2</code>s bit is overwritten with <code>0</code>, and the <code>64</code>s bit is overwritten with <code>1</code>.</p>
|
|
<p>The program then attempts to write the value <code>11</code> to memory address <code>8</code>. By expanding everything out to individual bits, the mask is applied as follows:</p>
|
|
<pre><code>value: 000000000000000000000000000000001011 (decimal 11)
|
|
mask: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
|
|
result: 00000000000000000000000000000<em>1</em>0010<em>0</em>1 (decimal 73)
|
|
</code></pre>
|
|
<p>So, because of the mask, the value <code>73</code> is written to memory address <code>8</code> instead. Then, the program tries to write <code>101</code> to address <code>7</code>:</p>
|
|
<pre><code>value: 000000000000000000000000000001100101 (decimal 101)
|
|
mask: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
|
|
result: 00000000000000000000000000000<em>1</em>1001<em>0</em>1 (decimal 101)
|
|
</code></pre>
|
|
<p>This time, the mask has no effect, as the bits it overwrote were already the values the mask tried to set. Finally, the program tries to write <code>0</code> to address <code>8</code>:</p>
|
|
<pre><code>value: 000000000000000000000000000000000000 (decimal 0)
|
|
mask: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
|
|
result: 00000000000000000000000000000<em>1</em>0000<em>0</em>0 (decimal 64)
|
|
</code></pre>
|
|
<p><code>64</code> is written to address <code>8</code> instead, overwriting the value that was there previously.</p>
|
|
<p>To initialize your ferry's docking program, you need the sum of all values left in memory after the initialization program completes. (The entire 36-bit address space begins initialized to the value <code>0</code> at every address.) In the above example, only two values in memory are not zero - <code>101</code> (at address <code>7</code>) and <code>64</code> (at address <code>8</code>) - producing a sum of <em><code>165</code></em>.</p>
|
|
<p>Execute the initialization program. <em>What is the sum of all values left in memory after it completes?</em></p>
|
|
</article>
|
|
<p>To begin, <a href="14/input" target="_blank">get your puzzle input</a>.</p>
|
|
<form method="post" action="14/answer"><input type="hidden" name="level" value="1"/><p>Answer: <input type="text" name="answer" autocomplete="off"/> <input type="submit" value="[Submit]"/></p></form>
|
|
<p>You can also <span class="share">[Share<span class="share-content">on
|
|
<a href="https://twitter.com/intent/tweet?text=%22Docking+Data%22+%2D+Day+14+%2D+Advent+of+Code+2020&url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F14&related=ericwastl&hashtags=AdventOfCode" target="_blank">Twitter</a>
|
|
<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=%22Docking+Data%22+%2D+Day+14+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F14'}else{return false;}" target="_blank">Mastodon</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('set', 'anonymizeIp', true);
|
|
ga('send', 'pageview');
|
|
</script>
|
|
<!-- /ga -->
|
|
</body>
|
|
</html> |