-
Notifications
You must be signed in to change notification settings - Fork 0
/
d08a.html
178 lines (176 loc) · 2.87 KB
/
d08a.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
<article class="day-desc">
<h2>
--- Day 8: Haunted Wasteland ---
</h2>
<p>
You're still riding a camel across Desert Island when you spot a sandstorm quickly approaching. When you turn to warn the Elf, she disappears before your eyes! To be fair, she had just finished warning you about
<em>
ghosts
</em>
a few minutes ago.
</p>
<p>
One of the camel's pouches is labeled "maps" - sure enough, it's full of documents (your puzzle input) about how to navigate the desert. At least, you're pretty sure that's what they are; one of the documents contains a list of left/right instructions, and the rest of the documents seem to describe some kind of
<em>
network
</em>
of labeled nodes.
</p>
<p>
It seems like you're meant to use the
<em>
left/right
</em>
instructions to
<em>
navigate the network
</em>
. Perhaps if you have the camel follow the same instructions, you can escape the haunted wasteland!
</p>
<p>
After examining the maps for a bit, two nodes stick out:
<code>
AAA
</code>
and
<code>
ZZZ
</code>
. You feel like
<code>
AAA
</code>
is where you are now, and you have to follow the left/right instructions until you reach
<code>
ZZZ
</code>
.
</p>
<p>
This format defines each
<em>
node
</em>
of the network individually. For example:
</p>
<pre>
<code>
RL
AAA = (BBB, CCC)
BBB = (DDD, EEE)
CCC = (ZZZ, GGG)
DDD = (DDD, DDD)
EEE = (EEE, EEE)
GGG = (GGG, GGG)
ZZZ = (ZZZ, ZZZ)
</code>
</pre>
<p>
Starting with
<code>
AAA
</code>
, you need to
<em>
look up the next element
</em>
based on the next left/right instruction in your input. In this example, start with
<code>
AAA
</code>
and go
<em>
right
</em>
(
<code>
R
</code>
) by choosing the right element of
<code>
AAA
</code>
,
<code>
<em>
CCC
</em>
</code>
. Then,
<code>
L
</code>
means to choose the
<em>
left
</em>
element of
<code>
CCC
</code>
,
<code>
<em>
ZZZ
</em>
</code>
. By following the left/right instructions, you reach
<code>
ZZZ
</code>
in
<code>
<em>
2
</em>
</code>
steps.
</p>
<p>
Of course, you might not find
<code>
ZZZ
</code>
right away. If you run out of left/right instructions, repeat the whole sequence of instructions as necessary:
<code>
RL
</code>
really means
<code>
RLRLRLRLRLRLRLRL...
</code>
and so on. For example, here is a situation that takes
<code>
<em>
6
</em>
</code>
steps to reach
<code>
ZZZ
</code>
:
</p>
<pre>
<code>
LLR
AAA = (BBB, BBB)
BBB = (AAA, ZZZ)
ZZZ = (ZZZ, ZZZ)
</code>
</pre>
<p>
Starting at
<code>
AAA
</code>
, follow the left/right instructions.
<em>
How many steps are required to reach
<code>
ZZZ
</code>
?
</em>
</p>
</article>