-
Notifications
You must be signed in to change notification settings - Fork 0
/
year2016_day22_puzzle.html
197 lines (134 loc) · 9.71 KB
/
year2016_day22_puzzle.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8"/>
<title>Day 22 - Advent of Code 2016</title>
<link rel="stylesheet" type="text/css" href="/static/style.css?31"/>
<link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?1" title="High Contrast"/>
<link rel="shortcut icon" href="/favicon.png"/>
<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>
</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 @was.tl on Bluesky, @[email protected] on
Mastodon, and @ericwastl on Twitter.
- Eric Wastl
-->
<body>
<div id="sidebar">
</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>952</code>.</p><p class="day-success">The first half of this puzzle is complete! It provides one gold star: *</p>
<article class="day-desc"><h2 id="part2">--- 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>
<form method="post" action="22/answer"><input type="hidden" name="level" value="2"/><p>Answer: <input type="text" name="answer" autocomplete="off"/> <input type="submit" value="[Submit]"/></p></form>
<p>Although it hasn't changed, you can still <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://bsky.app/intent/compose?text=I%27ve+completed+Part+One+of+%22Grid+Computing%22+%2D+Day+22+%2D+Advent+of+Code+2016+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F22" target="_blank">Bluesky</a>
<a href="https://twitter.com/intent/tweet?text=I%27ve+completed+Part+One+of+%22Grid+Computing%22+%2D+Day+22+%2D+Advent+of+Code+2016&url=https%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F22&related=ericwastl&hashtags=AdventOfCode" target="_blank">Twitter</a>
<a href="javascript:void(0);" onclick="var ms; try{ms=localStorage.getItem('mastodon.server')}finally{} if(typeof ms!=='string')ms=''; ms=prompt('Mastodon Server?',ms); if(typeof ms==='string' && ms.length){this.href='https://'+ms+'/share?text=I%27ve+completed+Part+One+of+%22Grid+Computing%22+%2D+Day+22+%2D+Advent+of+Code+2016+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F22';try{localStorage.setItem('mastodon.server',ms);}finally{}}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>