Removed needless directory
[advent-of-code-16.git] / day22.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 22 - Advent of Code 2016</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?9"/>
9 <link rel="shortcut icon" href="/favicon.ico?2"/>
10 </head><!--
11
12
13
14
15 Oh, hello! Funny seeing you here.
16
17 I appreciate your enthusiasm, but you aren't going to find much down here.
18 There certainly aren't clues to any of the puzzles. The best surprises don't
19 even appear in the source until you unlock them for real.
20
21 Please be careful with automated requests; I'm not Google, and I can only take
22 so much traffic. Please be considerate so that everyone gets to play.
23
24 If you're curious about how Advent of Code works, it's running on some custom
25 Perl code. Other than a few integrations (auth, analytics, ads, social media),
26 I built the whole thing myself, including the design, animations, prose, and
27 all of the puzzles.
28
29 The puzzles probably took the longest; the easiest ones were around 45 minutes
30 each, but the harder ones took 2-3 hours, and a few even longer than that. A
31 lot of effort went into building this thing - I hope you're enjoying playing it
32 as much as I enjoyed making it for you!
33
34 If you'd like to hang out, I'm @ericwastl on Twitter.
35
36 - Eric Wastl
37
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 <body>
89 <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>
90
91 <div id="sidebar">
92 <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>
93 <div id="ad">
94 <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
95 <!-- Advent of Code Wide Skyscraper -->
96 <ins class="adsbygoogle"
97 style="display:inline-block;width:160px;height:600px"
98 data-ad-client="ca-pub-9420604735624631"
99 data-ad-slot="8014013294"></ins>
100 <script>
101 (adsbygoogle = window.adsbygoogle || []).push({});
102 </script>
103 </div><!--/ad-->
104 </div><!--/sidebar-->
105
106 <main>
107 <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>
108 <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>
109 <ul>
110 <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>
111 <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>
112 </ul>
113 <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>
114 <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>
115 <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>
116 <ul>
117 <li>Node A is <em>not</em> empty (its <code>Used</code> is not zero).</li>
118 <li>Nodes A and B are <em>not the same</em> node.</li>
119 <li>The data on node A (its <code>Used</code>) <em>would fit</em> on node B (its <code>Avail</code>).</li>
120 </ul>
121 <p><em>How many viable pairs</em> of nodes are there?</p>
122 </article>
123 <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>
124 <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>
125 <p>For example, suppose you have the following grid:</p>
126 <pre><code>Filesystem Size Used Avail Use%
127 /dev/grid/node-x0-y0 10T 8T 2T 80%
128 /dev/grid/node-x0-y1 11T 6T 5T 54%
129 /dev/grid/node-x0-y2 32T 28T 4T 87%
130 /dev/grid/node-x1-y0 9T 7T 2T 77%
131 /dev/grid/node-x1-y1 8T 0T 8T 0%
132 /dev/grid/node-x1-y2 11T 7T 4T 63%
133 /dev/grid/node-x2-y0 10T 6T 4T 60%
134 /dev/grid/node-x2-y1 9T 8T 1T 88%
135 /dev/grid/node-x2-y2 9T 6T 3T 66%
136 </code></pre>
137 <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>
138 <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>
139 <pre><code>( 8T/10T) -- 7T/ 9T -- [ 6T/10T]
140 | | |
141 6T/11T -- 0T/ 8T -- 8T/ 9T
142 | | |
143 28T/32T -- 7T/11T -- 6T/ 9T
144 </code></pre>
145 <p>The node you can access directly is in parentheses; the data you want starts in the node marked by square brackets.</p>
146 <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>
147 <pre><code>(.) . G
148 . _ .
149 # . .
150 </code></pre>
151 <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>
152 <ul>
153 <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
154 . . .
155 # . .
156 </code></pre>
157 <li><p>Move the goal data from <code>node-y0-x2</code> to <code>node-y0-x1</code>:</p><pre><code>(.) G _
158 . . .
159 # . .
160 </code></pre>
161 <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 .
162 . . _
163 # . .
164 </code></pre>
165 <li><p>Move the data from <code>node-y1-x1</code> to <code>node-y1-x2</code>:</p><pre><code>(.) G .
166 . _ .
167 # . .
168 </code></pre>
169 <li><p>Move the data from <code>node-y1-x0</code> to <code>node-y1-x1</code>:</p><pre><code>(.) G .
170 _ . .
171 # . .
172 </code></pre>
173 <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 .
174 . . .
175 # . .
176 </code></pre>
177 </li>
178 <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) _ .
179 . . .
180 # . .
181 </code></pre>
182 </li>
183 </ul>
184 <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>
185 <p><em>What is the fewest number of steps</em> required to move your goal data to <code>node-x0-y0</code>?</p>
186 </article>
187 <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>
188 <p>At this point, you should <a href="/2016">return to your advent calendar</a> and try another puzzle.</p>
189 <p>If you still want to see it, you can <a href="22/input" target="_blank">get your puzzle input</a>.</p>
190 <p>You can also <span class="share">[Share<span class="share-content">on
191 <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>
192 <a href="https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F22" target="_blank">Google+</a>
193 <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
194 ></span>]</span> this puzzle.</p>
195 </main>
196
197 <!-- ga -->
198 <script>
199 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
200 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
201 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
202 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
203 ga('create', 'UA-69522494-1', 'auto');
204 ga('send', 'pageview');
205 </script>
206 <!-- /ga -->
207 </body>
208 </html>