-
Notifications
You must be signed in to change notification settings - Fork 0
/
23_Amphipods_ManualRelocations.txt
319 lines (268 loc) · 7.17 KB
/
23_Amphipods_ManualRelocations.txt
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
--- Day 23: Amphipod ---
A group of amphipods notice your fancy submarine and flag you down. "With such an impressive shell," one amphipod says, "surely you can help us with a question that has stumped our best scientists."
They go on to explain that a group of timid, stubborn amphipods live in a nearby burrow. Four types of amphipods live there: Amber (A), Bronze (B), Copper (C), and Desert (D). They live in a burrow that consists of a hallway and four side rooms. The side rooms are initially full of amphipods, and the hallway is initially empty.
They give you a diagram of the situation (your puzzle input), including locations of each amphipod (A, B, C, or D, each of which is occupying an otherwise open space), walls (#), and open space (.).
For example:
#############
#...........#
###B#C#B#D###
#A#D#C#A#
#########
The amphipods would like a method to organize every amphipod into side rooms so that each side room contains one type of amphipod and the types are sorted A-D going left to right, like this:
#############
#...........#
###A#B#C#D###
#A#B#C#D#
#########
Amphipods can move up, down, left, or right so long as they are moving into an unoccupied open space. Each type of amphipod requires a different amount of energy to move one step: Amber amphipods require 1 energy per step, Bronze amphipods require 10 energy, Copper amphipods require 100, and Desert ones require 1000. The amphipods would like you to find a way to organize the amphipods that requires the least total energy.
However, because they are timid and stubborn, the amphipods have some extra rules:
Amphipods will never stop on the space immediately outside any room. They can move into that space so long as they immediately continue moving. (Specifically, this refers to the four open spaces in the hallway that are directly above an amphipod starting position.)
Amphipods will never move from the hallway into a room unless that room is their destination room and that room contains no amphipods which do not also have that room as their own destination. If an amphipod's starting room is not its destination room, it can stay in that room until it leaves the room. (For example, an Amber amphipod will not move from the hallway into the right three rooms, and will only move into the leftmost room if that room is empty or if it only contains other Amber amphipods.)
Once an amphipod stops moving in the hallway, it will stay in that spot until it can move into a room. (That is, once any amphipod starts moving, any other amphipods currently in the hallway are locked in place and will not move again until they can move fully into a room.)
In the above example, the amphipods can be organized using a minimum of 12521 energy. One way to do this is shown below.
Starting configuration:
#############
#...........#
###B#C#B#D###
#A#D#C#A#
#########
One Bronze amphipod moves into the hallway, taking 4 steps and using 40 energy:
#############
#...B.......#
###B#C#.#D###
#A#D#C#A#
#########
The only Copper amphipod not in its side room moves there, taking 4 steps and using 400 energy:
#############
#...B.......#
###B#.#C#D###
#A#D#C#A#
#########
A Desert amphipod moves out of the way, taking 3 steps and using 3000 energy, and then the Bronze amphipod takes its place, taking 3 steps and using 30 energy:
#############
#.....D.....#
###B#.#C#D###
#A#B#C#A#
#########
The leftmost Bronze amphipod moves to its room using 40 energy:
#############
#.....D.....#
###.#B#C#D###
#A#B#C#A#
#########
Both amphipods in the rightmost room move into the hallway, using 2003 energy in total:
#############
#.....D.D.A.#
###.#B#C#.###
#A#B#C#.#
#########
Both Desert amphipods move into the rightmost room using 7000 energy:
#############
#.........A.#
###.#B#C#D###
#A#B#C#D#
#########
Finally, the last Amber amphipod moves into its room, using 8 energy:
#############
#...........#
###A#B#C#D###
#A#B#C#D#
#########
What is the least energy required to organize the amphipods?
Your puzzle answer was 13558.
--- Part Two ---
As you prepare to give the amphipods your solution, you notice that the diagram they handed you was actually folded up. As you unfold it, you discover an extra part of the diagram.
Between the first and second lines of text that contain amphipod starting positions, insert the following lines:
#D#C#B#A#
#D#B#A#C#
So, the above example now becomes:
#############
#...........#
###B#C#B#D###
#D#C#B#A#
#D#B#A#C#
#A#D#C#A#
#########
The amphipods still want to be organized into rooms similar to before:
#############
#...........#
###A#B#C#D###
#A#B#C#D#
#A#B#C#D#
#A#B#C#D#
#########
In this updated example, the least energy required to organize these amphipods is 44169:
#############
#...........#
###B#C#B#D###
#D#C#B#A#
#D#B#A#C#
#A#D#C#A#
#########
#############
#..........D#
###B#C#B#.###
#D#C#B#A#
#D#B#A#C#
#A#D#C#A#
#########
#############
#A.........D#
###B#C#B#.###
#D#C#B#.#
#D#B#A#C#
#A#D#C#A#
#########
#############
#A........BD#
###B#C#.#.###
#D#C#B#.#
#D#B#A#C#
#A#D#C#A#
#########
#############
#A......B.BD#
###B#C#.#.###
#D#C#.#.#
#D#B#A#C#
#A#D#C#A#
#########
#############
#AA.....B.BD#
###B#C#.#.###
#D#C#.#.#
#D#B#.#C#
#A#D#C#A#
#########
#############
#AA.....B.BD#
###B#.#.#.###
#D#C#.#.#
#D#B#C#C#
#A#D#C#A#
#########
#############
#AA.....B.BD#
###B#.#.#.###
#D#.#C#.#
#D#B#C#C#
#A#D#C#A#
#########
#############
#AA...B.B.BD#
###B#.#.#.###
#D#.#C#.#
#D#.#C#C#
#A#D#C#A#
#########
#############
#AA.D.B.B.BD#
###B#.#.#.###
#D#.#C#.#
#D#.#C#C#
#A#.#C#A#
#########
#############
#AA.D...B.BD#
###B#.#.#.###
#D#.#C#.#
#D#.#C#C#
#A#B#C#A#
#########
#############
#AA.D.....BD#
###B#.#.#.###
#D#.#C#.#
#D#B#C#C#
#A#B#C#A#
#########
#############
#AA.D......D#
###B#.#.#.###
#D#B#C#.#
#D#B#C#C#
#A#B#C#A#
#########
#############
#AA.D......D#
###B#.#C#.###
#D#B#C#.#
#D#B#C#.#
#A#B#C#A#
#########
#############
#AA.D.....AD#
###B#.#C#.###
#D#B#C#.#
#D#B#C#.#
#A#B#C#.#
#########
#############
#AA.......AD#
###B#.#C#.###
#D#B#C#.#
#D#B#C#.#
#A#B#C#D#
#########
#############
#AA.......AD#
###.#B#C#.###
#D#B#C#.#
#D#B#C#.#
#A#B#C#D#
#########
#############
#AA.......AD#
###.#B#C#.###
#.#B#C#.#
#D#B#C#D#
#A#B#C#D#
#########
#############
#AA.D.....AD#
###.#B#C#.###
#.#B#C#.#
#.#B#C#D#
#A#B#C#D#
#########
#############
#A..D.....AD#
###.#B#C#.###
#.#B#C#.#
#A#B#C#D#
#A#B#C#D#
#########
#############
#...D.....AD#
###.#B#C#.###
#A#B#C#.#
#A#B#C#D#
#A#B#C#D#
#########
#############
#.........AD#
###.#B#C#.###
#A#B#C#D#
#A#B#C#D#
#A#B#C#D#
#########
#############
#..........D#
###A#B#C#.###
#A#B#C#D#
#A#B#C#D#
#A#B#C#D#
#########
#############
#...........#
###A#B#C#D###
#A#B#C#D#
#A#B#C#D#
#A#B#C#D#
#########
Using the initial configuration from the full diagram, what is the least energy required to organize the amphipods?
Your puzzle answer was 56982.
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, all that is left is for you to admire your Advent calendar.
If you still want to see it, you can get your puzzle input.
You can also [Share] this puzzle.