Day 22, with stack build system
[advent-of-code-16.git] / day22.html
diff --git a/day22.html b/day22.html
new file mode 100644 (file)
index 0000000..3a820ab
--- /dev/null
@@ -0,0 +1,208 @@
+<!DOCTYPE html>
+<html lang="en-us">
+<head>
+<meta charset="utf-8"/>
+<title>Day 22 - Advent of Code 2016</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?9"/>
+<link rel="shortcut icon" href="/favicon.ico?2"/>
+</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 probably took the longest; the easiest ones were around 45 minutes
+each, but the harder ones took 2-3 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="/2016/about">[About]</a></li><li><a href="/2016/support">[AoC++]</a></li><li><a href="/2016/events">[Events]</a></li><li><a href="/2016/settings">[Settings]</a></li><li><a href="/2016/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <span class="supporter">(AoC++)</span> <span class="star-count">44*</span></div></div><div><h1 class="title-event">&nbsp;<span class="title-event-wrap">{'year':</span><a href="/2016">2016</a><span class="title-event-wrap">}</span></h1><nav><ul><li><a href="/2016">[Calendar]</a></li><li><a href="/2016/leaderboard">[Leaderboard]</a></li><li><a href="/2016/stats">[Stats]</a></li><li><a href="/2016/sponsors">[Sponsors]</a></li></ul></nav></div></header>
+
+<div id="sidebar">
+<div id="sponsor"><div class="quiet">Our <a href="/2016/sponsors">sponsors</a> help make AoC possible:</div><p><a href="https://info.esparklearning.com/join-our-team-full-stack-engineer" target="_blank" onclick="if(ga)ga('send','event','sponsor','click',this.href);">eSpark Learning</a> - Solve the greatest puzzle of our day - transform education</p></div>
+<div id="ad">
+<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
+<!-- Advent of Code Wide Skyscraper -->
+<ins class="adsbygoogle"
+     style="display:inline-block;width:160px;height:600px"
+     data-ad-client="ca-pub-9420604735624631"
+     data-ad-slot="8014013294"></ins>
+<script>
+(adsbygoogle = window.adsbygoogle || []).push({});
+</script>
+</div><!--/ad-->
+</div><!--/sidebar-->
+
+<main>
+<article class="day-desc"><h2>--- Day 22: Grid Computing ---</h2><p>You gain access to a massive storage cluster arranged in a grid; each storage node is only connected to the four nodes directly adjacent to it (three if the node is on an edge, two if it's in a corner).</p>
+<p>You can directly access data <em>only</em> on node <code>/dev/grid/node-x0-y0</code>, but you can perform some limited actions on the other nodes:</p>
+<ul>
+<li>You can get the disk usage of all nodes (via <a href="https://en.wikipedia.org/wiki/Df_(Unix)#Example"><code>df</code></a>). The result of doing this is in your puzzle input.</li>
+<li>You can instruct a node to <span title="You suspect someone misunderstood the x86 MOV instruction."><em>move</em></span> (not copy) <em>all</em> of its data to an adjacent node (if the destination node has enough space to receive the data). The sending node is left empty after this operation.</li>
+</ul>
+<p>Nodes are named by their position: the node named <code>node-x10-y10</code> is adjacent to nodes <code>node-x9-y10</code>, <code>node-x11-y10</code>, <code>node-x10-y9</code>, and <code>node-x10-y11</code>.</p>
+<p>Before you begin, you need to understand the arrangement of data on these nodes. Even though you can only move data between directly connected nodes, you're going to need to rearrange a lot of the data to get access to the data you need.  Therefore, you need to work out how you might be able to shift data around.</p>
+<p>To do this, you'd like to count the number of <em>viable pairs</em> of nodes.  A viable pair is any two nodes (A,B), <em>regardless of whether they are directly connected</em>, such that:</p>
+<ul>
+<li>Node A is <em>not</em> empty (its <code>Used</code> is not zero).</li>
+<li>Nodes A and B are <em>not the same</em> node.</li>
+<li>The data on node A (its <code>Used</code>) <em>would fit</em> on node B (its <code>Avail</code>).</li>
+</ul>
+<p><em>How many viable pairs</em> of nodes are there?</p>
+</article>
+<p>Your puzzle answer was <code>1034</code>.</p><article class="day-desc"><h2>--- Part Two ---</h2><p>Now that you have a better understanding of the grid, it's time to get to work.</p>
+<p>Your goal is to gain access to the data which begins in the node with <code>y=0</code> and the <em>highest <code>x</code></em> (that is, the node in the top-right corner).</p>
+<p>For example, suppose you have the following grid:</p>
+<pre><code>Filesystem            Size  Used  Avail  Use%
+/dev/grid/node-x0-y0   10T    8T     2T   80%
+/dev/grid/node-x0-y1   11T    6T     5T   54%
+/dev/grid/node-x0-y2   32T   28T     4T   87%
+/dev/grid/node-x1-y0    9T    7T     2T   77%
+/dev/grid/node-x1-y1    8T    0T     8T    0%
+/dev/grid/node-x1-y2   11T    7T     4T   63%
+/dev/grid/node-x2-y0   10T    6T     4T   60%
+/dev/grid/node-x2-y1    9T    8T     1T   88%
+/dev/grid/node-x2-y2    9T    6T     3T   66%
+</code></pre>
+<p>In this example, you have a storage grid <code>3</code> nodes wide and <code>3</code> nodes tall.  The node you can access directly, <code>node-x0-y0</code>, is almost full. The node containing the data you want to access, <code>node-x2-y0</code> (because it has <code>y=0</code> and the highest <code>x</code> value), contains 6 <a href="https://en.wikipedia.org/wiki/Terabyte">terabytes</a> of data - enough to fit on your node, if only you could make enough space to move it there.</p>
+<p>Fortunately, <code>node-x1-y1</code> looks like it has enough free space to enable you to move some of this data around.  In fact, it seems like all of the nodes have enough space to hold any node's data (except <code>node-x0-y2</code>, which is much larger, very full, and not moving any time soon). So, initially, the grid's capacities and connections look like this:</p>
+<pre><code>( 8T/10T) --  7T/ 9T -- [ 6T/10T]
+    |           |           |
+  6T/11T  --  0T/ 8T --   8T/ 9T
+    |           |           |
+ 28T/32T  --  7T/11T --   6T/ 9T
+</code></pre>
+<p>The node you can access directly is in parentheses; the data you want starts in the node marked by square brackets.</p>
+<p>In this example, most of the nodes are interchangable: they're full enough that no other node's data would fit, but small enough that their data could be moved around. Let's draw these nodes as <code>.</code>. The exceptions are the empty node, which we'll draw as <code>_</code>, and the very large, very full node, which we'll draw as <code>#</code>. Let's also draw the goal data as <code>G</code>. Then, it looks like this:</p>
+<pre><code>(.) .  G
+ .  _  .
+ #  .  .
+</code></pre>
+<p>The goal is to move the data in the top right, <code>G</code>, to the node in parentheses. To do this, we can issue some commands to the grid and rearrange the data:</p>
+<ul>
+<li><p>Move data from <code>node-y0-x1</code> to <code>node-y1-x1</code>, leaving node <code>node-y0-x1</code> empty:</p><pre><code>(.) _  G
+ .  .  .
+ #  .  .
+</code></pre>
+<li><p>Move the goal data from <code>node-y0-x2</code> to <code>node-y0-x1</code>:</p><pre><code>(.) G  _
+ .  .  .
+ #  .  .
+</code></pre>
+<li><p>At this point, we're quite close. However, we have no deletion command, so we have to move some more data around. So, next, we move the data from <code>node-y1-x2</code> to <code>node-y0-x2</code>:</p><pre><code>(.) G  .
+ .  .  _
+ #  .  .
+</code></pre>
+<li><p>Move the data from <code>node-y1-x1</code> to <code>node-y1-x2</code>:</p><pre><code>(.) G  .
+ .  _  .
+ #  .  .
+</code></pre>
+<li><p>Move the data from <code>node-y1-x0</code> to <code>node-y1-x1</code>:</p><pre><code>(.) G  .
+ _  .  .
+ #  .  .
+</code></pre>
+<li><p>Next, we can free up space on our node by moving the data from <code>node-y0-x0</code> to <code>node-y1-x0</code>:</p><pre><code>(_) G  .
+ .  .  .
+ #  .  .
+</code></pre>
+</li>
+<li><p>Finally, we can access the goal data by moving the it from <code>node-y0-x1</code> to <code>node-y0-x0</code>:</p><pre><code>(G) _  .
+ .  .  .
+ #  .  .
+</code></pre>
+</li>
+</ul>
+<p>So, after <code>7</code> steps, we've accessed the data we want. Unfortunately, each of these moves takes time, and we need to be efficient:</p>
+<p><em>What is the fewest number of steps</em> required to move your goal data to <code>node-x0-y0</code>?</p>
+</article>
+<p>Your puzzle answer was <code>261</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="/2016">return to your advent calendar</a> and try another puzzle.</p>
+<p>If you still want to see it, you can <a href="22/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+%22Grid+Computing%22+%2D+Day+22+%2D+Advent+of+Code+2016&amp;url=http%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F22&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
+  <a href="https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F22" target="_blank">Google+</a>
+  <a href="http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F22&amp;title=I%27ve+completed+%22Grid+Computing%22+%2D+Day+22+%2D+Advent+of+Code+2016" 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