diff options
Diffstat (limited to '2022')
-rw-r--r-- | 2022/day5/example | 9 | ||||
-rw-r--r-- | 2022/day5/input | 512 | ||||
-rw-r--r-- | 2022/day5/part1/Cargo.toml | 10 | ||||
-rw-r--r-- | 2022/day5/part1/src/main.rs | 62 |
4 files changed, 593 insertions, 0 deletions
diff --git a/2022/day5/example b/2022/day5/example new file mode 100644 index 0000000..42ef47f --- /dev/null +++ b/2022/day5/example | |||
@@ -0,0 +1,9 @@ | |||
1 | [D] | ||
2 | [N] [C] | ||
3 | [Z] [M] [P] | ||
4 | 1 2 3 | ||
5 | |||
6 | move 1 from 2 to 1 | ||
7 | move 3 from 1 to 3 | ||
8 | move 2 from 2 to 1 | ||
9 | move 1 from 1 to 2 | ||
diff --git a/2022/day5/input b/2022/day5/input new file mode 100644 index 0000000..76316f1 --- /dev/null +++ b/2022/day5/input | |||
@@ -0,0 +1,512 @@ | |||
1 | [J] [F] [M] | ||
2 | [Z] [F] [G] [Q] [F] | ||
3 | [G] [P] [H] [Z] [S] [Q] | ||
4 | [V] [W] [Z] [P] [D] [G] [P] | ||
5 | [T] [D] [S] [Z] [N] [W] [B] [N] | ||
6 | [D] [M] [R] [J] [J] [P] [V] [P] [J] | ||
7 | [B] [R] [C] [T] [C] [V] [C] [B] [P] | ||
8 | [N] [S] [V] [R] [T] [N] [G] [Z] [W] | ||
9 | 1 2 3 4 5 6 7 8 9 | ||
10 | |||
11 | move 2 from 4 to 6 | ||
12 | move 1 from 9 to 5 | ||
13 | move 3 from 2 to 4 | ||
14 | move 8 from 4 to 7 | ||
15 | move 2 from 9 to 7 | ||
16 | move 3 from 8 to 3 | ||
17 | move 2 from 1 to 2 | ||
18 | move 5 from 7 to 9 | ||
19 | move 1 from 9 to 4 | ||
20 | move 1 from 8 to 3 | ||
21 | move 1 from 3 to 4 | ||
22 | move 2 from 4 to 9 | ||
23 | move 7 from 3 to 5 | ||
24 | move 6 from 1 to 8 | ||
25 | move 11 from 7 to 9 | ||
26 | move 12 from 5 to 3 | ||
27 | move 6 from 6 to 9 | ||
28 | move 3 from 3 to 8 | ||
29 | move 4 from 2 to 7 | ||
30 | move 3 from 5 to 7 | ||
31 | move 1 from 5 to 7 | ||
32 | move 2 from 2 to 5 | ||
33 | move 1 from 5 to 2 | ||
34 | move 5 from 8 to 9 | ||
35 | move 7 from 7 to 2 | ||
36 | move 3 from 8 to 7 | ||
37 | move 1 from 8 to 9 | ||
38 | move 4 from 3 to 6 | ||
39 | move 1 from 5 to 1 | ||
40 | move 9 from 9 to 6 | ||
41 | move 7 from 9 to 6 | ||
42 | move 20 from 6 to 5 | ||
43 | move 12 from 9 to 8 | ||
44 | move 5 from 5 to 1 | ||
45 | move 3 from 7 to 4 | ||
46 | move 6 from 2 to 7 | ||
47 | move 2 from 3 to 1 | ||
48 | move 4 from 3 to 8 | ||
49 | move 1 from 4 to 1 | ||
50 | move 7 from 7 to 5 | ||
51 | move 4 from 8 to 2 | ||
52 | move 3 from 6 to 2 | ||
53 | move 3 from 2 to 9 | ||
54 | move 4 from 1 to 7 | ||
55 | move 2 from 1 to 2 | ||
56 | move 3 from 9 to 5 | ||
57 | move 11 from 8 to 5 | ||
58 | move 1 from 6 to 9 | ||
59 | move 1 from 8 to 5 | ||
60 | move 1 from 1 to 2 | ||
61 | move 24 from 5 to 4 | ||
62 | move 2 from 1 to 6 | ||
63 | move 11 from 5 to 4 | ||
64 | move 2 from 7 to 9 | ||
65 | move 1 from 6 to 2 | ||
66 | move 4 from 2 to 1 | ||
67 | move 28 from 4 to 2 | ||
68 | move 1 from 7 to 8 | ||
69 | move 9 from 2 to 5 | ||
70 | move 2 from 9 to 6 | ||
71 | move 4 from 4 to 2 | ||
72 | move 1 from 7 to 4 | ||
73 | move 3 from 4 to 7 | ||
74 | move 1 from 6 to 9 | ||
75 | move 21 from 2 to 3 | ||
76 | move 3 from 1 to 6 | ||
77 | move 5 from 6 to 2 | ||
78 | move 7 from 2 to 3 | ||
79 | move 1 from 9 to 3 | ||
80 | move 1 from 8 to 4 | ||
81 | move 1 from 7 to 8 | ||
82 | move 3 from 5 to 8 | ||
83 | move 1 from 1 to 7 | ||
84 | move 2 from 7 to 9 | ||
85 | move 2 from 8 to 4 | ||
86 | move 1 from 9 to 2 | ||
87 | move 1 from 8 to 6 | ||
88 | move 11 from 3 to 4 | ||
89 | move 1 from 7 to 8 | ||
90 | move 6 from 5 to 9 | ||
91 | move 2 from 8 to 7 | ||
92 | move 1 from 6 to 5 | ||
93 | move 7 from 3 to 8 | ||
94 | move 9 from 3 to 6 | ||
95 | move 1 from 8 to 3 | ||
96 | move 1 from 7 to 4 | ||
97 | move 2 from 3 to 5 | ||
98 | move 4 from 5 to 7 | ||
99 | move 4 from 6 to 8 | ||
100 | move 2 from 7 to 9 | ||
101 | move 11 from 4 to 2 | ||
102 | move 1 from 4 to 2 | ||
103 | move 6 from 8 to 9 | ||
104 | move 1 from 7 to 1 | ||
105 | move 1 from 3 to 7 | ||
106 | move 3 from 7 to 8 | ||
107 | move 6 from 8 to 9 | ||
108 | move 6 from 4 to 8 | ||
109 | move 18 from 9 to 3 | ||
110 | move 1 from 5 to 8 | ||
111 | move 5 from 6 to 5 | ||
112 | move 6 from 8 to 1 | ||
113 | move 3 from 5 to 4 | ||
114 | move 1 from 9 to 8 | ||
115 | move 3 from 4 to 8 | ||
116 | move 15 from 3 to 6 | ||
117 | move 2 from 5 to 9 | ||
118 | move 3 from 3 to 1 | ||
119 | move 9 from 6 to 4 | ||
120 | move 2 from 1 to 5 | ||
121 | move 2 from 5 to 8 | ||
122 | move 6 from 4 to 2 | ||
123 | move 6 from 1 to 6 | ||
124 | move 3 from 4 to 6 | ||
125 | move 6 from 9 to 1 | ||
126 | move 4 from 2 to 1 | ||
127 | move 7 from 8 to 1 | ||
128 | move 1 from 6 to 7 | ||
129 | move 17 from 1 to 5 | ||
130 | move 1 from 7 to 1 | ||
131 | move 5 from 2 to 1 | ||
132 | move 1 from 8 to 6 | ||
133 | move 11 from 6 to 4 | ||
134 | move 2 from 2 to 3 | ||
135 | move 3 from 1 to 8 | ||
136 | move 7 from 2 to 5 | ||
137 | move 4 from 6 to 7 | ||
138 | move 4 from 1 to 5 | ||
139 | move 15 from 5 to 9 | ||
140 | move 2 from 3 to 7 | ||
141 | move 2 from 8 to 2 | ||
142 | move 1 from 1 to 9 | ||
143 | move 6 from 2 to 6 | ||
144 | move 7 from 5 to 6 | ||
145 | move 5 from 7 to 3 | ||
146 | move 1 from 6 to 1 | ||
147 | move 2 from 3 to 4 | ||
148 | move 1 from 3 to 4 | ||
149 | move 5 from 6 to 4 | ||
150 | move 14 from 9 to 2 | ||
151 | move 1 from 8 to 9 | ||
152 | move 1 from 7 to 8 | ||
153 | move 1 from 9 to 6 | ||
154 | move 2 from 9 to 5 | ||
155 | move 1 from 1 to 2 | ||
156 | move 7 from 6 to 9 | ||
157 | move 1 from 3 to 4 | ||
158 | move 8 from 5 to 2 | ||
159 | move 1 from 6 to 7 | ||
160 | move 1 from 7 to 4 | ||
161 | move 1 from 8 to 4 | ||
162 | move 1 from 3 to 9 | ||
163 | move 7 from 9 to 5 | ||
164 | move 1 from 9 to 1 | ||
165 | move 6 from 5 to 1 | ||
166 | move 8 from 2 to 4 | ||
167 | move 1 from 5 to 6 | ||
168 | move 1 from 6 to 7 | ||
169 | move 1 from 7 to 9 | ||
170 | move 7 from 2 to 9 | ||
171 | move 1 from 9 to 4 | ||
172 | move 3 from 9 to 1 | ||
173 | move 1 from 9 to 6 | ||
174 | move 11 from 2 to 8 | ||
175 | move 9 from 1 to 8 | ||
176 | move 1 from 6 to 4 | ||
177 | move 1 from 1 to 9 | ||
178 | move 12 from 4 to 2 | ||
179 | move 4 from 9 to 3 | ||
180 | move 3 from 4 to 6 | ||
181 | move 9 from 8 to 6 | ||
182 | move 12 from 4 to 9 | ||
183 | move 8 from 6 to 3 | ||
184 | move 8 from 2 to 7 | ||
185 | move 11 from 3 to 4 | ||
186 | move 2 from 2 to 7 | ||
187 | move 2 from 6 to 1 | ||
188 | move 1 from 2 to 3 | ||
189 | move 2 from 6 to 2 | ||
190 | move 3 from 2 to 6 | ||
191 | move 2 from 1 to 6 | ||
192 | move 1 from 6 to 1 | ||
193 | move 1 from 6 to 4 | ||
194 | move 2 from 6 to 3 | ||
195 | move 1 from 6 to 5 | ||
196 | move 4 from 3 to 8 | ||
197 | move 12 from 4 to 5 | ||
198 | move 5 from 9 to 7 | ||
199 | move 3 from 8 to 7 | ||
200 | move 1 from 9 to 1 | ||
201 | move 3 from 8 to 2 | ||
202 | move 13 from 5 to 6 | ||
203 | move 1 from 2 to 9 | ||
204 | move 13 from 6 to 7 | ||
205 | move 7 from 9 to 6 | ||
206 | move 2 from 4 to 6 | ||
207 | move 1 from 8 to 6 | ||
208 | move 1 from 1 to 6 | ||
209 | move 1 from 2 to 9 | ||
210 | move 1 from 2 to 3 | ||
211 | move 12 from 7 to 9 | ||
212 | move 7 from 8 to 4 | ||
213 | move 1 from 1 to 3 | ||
214 | move 2 from 7 to 9 | ||
215 | move 15 from 7 to 4 | ||
216 | move 8 from 6 to 3 | ||
217 | move 1 from 8 to 9 | ||
218 | move 1 from 7 to 2 | ||
219 | move 10 from 3 to 5 | ||
220 | move 6 from 5 to 9 | ||
221 | move 1 from 2 to 8 | ||
222 | move 1 from 5 to 8 | ||
223 | move 2 from 8 to 9 | ||
224 | move 10 from 4 to 9 | ||
225 | move 20 from 9 to 6 | ||
226 | move 1 from 7 to 6 | ||
227 | move 4 from 9 to 3 | ||
228 | move 1 from 5 to 9 | ||
229 | move 4 from 4 to 9 | ||
230 | move 8 from 9 to 7 | ||
231 | move 2 from 5 to 1 | ||
232 | move 7 from 4 to 3 | ||
233 | move 8 from 3 to 2 | ||
234 | move 6 from 9 to 8 | ||
235 | move 1 from 3 to 7 | ||
236 | move 1 from 3 to 1 | ||
237 | move 7 from 7 to 8 | ||
238 | move 13 from 8 to 3 | ||
239 | move 2 from 2 to 8 | ||
240 | move 1 from 8 to 2 | ||
241 | move 1 from 4 to 1 | ||
242 | move 1 from 1 to 8 | ||
243 | move 2 from 8 to 2 | ||
244 | move 24 from 6 to 2 | ||
245 | move 2 from 7 to 8 | ||
246 | move 5 from 3 to 4 | ||
247 | move 25 from 2 to 6 | ||
248 | move 5 from 4 to 9 | ||
249 | move 2 from 8 to 7 | ||
250 | move 2 from 7 to 3 | ||
251 | move 4 from 6 to 2 | ||
252 | move 2 from 6 to 4 | ||
253 | move 9 from 2 to 3 | ||
254 | move 11 from 3 to 7 | ||
255 | move 10 from 7 to 8 | ||
256 | move 1 from 7 to 9 | ||
257 | move 3 from 2 to 4 | ||
258 | move 8 from 8 to 2 | ||
259 | move 1 from 2 to 6 | ||
260 | move 2 from 4 to 1 | ||
261 | move 1 from 8 to 2 | ||
262 | move 1 from 6 to 9 | ||
263 | move 1 from 8 to 3 | ||
264 | move 6 from 9 to 7 | ||
265 | move 2 from 9 to 1 | ||
266 | move 9 from 6 to 8 | ||
267 | move 7 from 2 to 3 | ||
268 | move 7 from 8 to 2 | ||
269 | move 10 from 6 to 8 | ||
270 | move 7 from 1 to 2 | ||
271 | move 9 from 3 to 2 | ||
272 | move 5 from 3 to 8 | ||
273 | move 4 from 7 to 2 | ||
274 | move 2 from 3 to 2 | ||
275 | move 12 from 2 to 3 | ||
276 | move 6 from 4 to 2 | ||
277 | move 1 from 7 to 6 | ||
278 | move 5 from 3 to 5 | ||
279 | move 16 from 8 to 4 | ||
280 | move 12 from 2 to 7 | ||
281 | move 5 from 5 to 7 | ||
282 | move 1 from 8 to 3 | ||
283 | move 1 from 6 to 4 | ||
284 | move 17 from 7 to 4 | ||
285 | move 1 from 7 to 1 | ||
286 | move 1 from 1 to 9 | ||
287 | move 1 from 9 to 5 | ||
288 | move 11 from 4 to 9 | ||
289 | move 10 from 2 to 3 | ||
290 | move 1 from 5 to 4 | ||
291 | move 1 from 9 to 2 | ||
292 | move 2 from 2 to 1 | ||
293 | move 1 from 2 to 3 | ||
294 | move 23 from 4 to 5 | ||
295 | move 7 from 9 to 7 | ||
296 | move 3 from 9 to 1 | ||
297 | move 20 from 5 to 6 | ||
298 | move 3 from 5 to 8 | ||
299 | move 1 from 4 to 1 | ||
300 | move 2 from 8 to 3 | ||
301 | move 4 from 6 to 4 | ||
302 | move 7 from 7 to 2 | ||
303 | move 1 from 8 to 4 | ||
304 | move 19 from 3 to 9 | ||
305 | move 5 from 1 to 7 | ||
306 | move 7 from 2 to 6 | ||
307 | move 3 from 7 to 5 | ||
308 | move 2 from 3 to 4 | ||
309 | move 1 from 5 to 4 | ||
310 | move 1 from 1 to 4 | ||
311 | move 1 from 7 to 6 | ||
312 | move 13 from 6 to 7 | ||
313 | move 6 from 9 to 3 | ||
314 | move 1 from 3 to 5 | ||
315 | move 2 from 3 to 4 | ||
316 | move 2 from 6 to 2 | ||
317 | move 3 from 4 to 3 | ||
318 | move 8 from 9 to 1 | ||
319 | move 2 from 2 to 1 | ||
320 | move 8 from 6 to 7 | ||
321 | move 2 from 9 to 4 | ||
322 | move 20 from 7 to 1 | ||
323 | move 2 from 7 to 5 | ||
324 | move 2 from 5 to 1 | ||
325 | move 8 from 1 to 8 | ||
326 | move 8 from 8 to 6 | ||
327 | move 1 from 6 to 9 | ||
328 | move 8 from 6 to 1 | ||
329 | move 1 from 5 to 3 | ||
330 | move 7 from 3 to 2 | ||
331 | move 1 from 5 to 2 | ||
332 | move 2 from 9 to 7 | ||
333 | move 1 from 5 to 8 | ||
334 | move 18 from 1 to 4 | ||
335 | move 1 from 8 to 9 | ||
336 | move 3 from 2 to 3 | ||
337 | move 2 from 7 to 4 | ||
338 | move 5 from 2 to 4 | ||
339 | move 3 from 3 to 8 | ||
340 | move 8 from 1 to 7 | ||
341 | move 2 from 9 to 2 | ||
342 | move 32 from 4 to 5 | ||
343 | move 1 from 9 to 7 | ||
344 | move 1 from 2 to 1 | ||
345 | move 6 from 1 to 6 | ||
346 | move 1 from 2 to 4 | ||
347 | move 3 from 8 to 1 | ||
348 | move 3 from 6 to 5 | ||
349 | move 1 from 3 to 6 | ||
350 | move 2 from 1 to 9 | ||
351 | move 4 from 4 to 7 | ||
352 | move 31 from 5 to 4 | ||
353 | move 4 from 5 to 6 | ||
354 | move 1 from 6 to 1 | ||
355 | move 7 from 6 to 5 | ||
356 | move 1 from 9 to 4 | ||
357 | move 19 from 4 to 2 | ||
358 | move 1 from 5 to 9 | ||
359 | move 5 from 5 to 6 | ||
360 | move 3 from 4 to 2 | ||
361 | move 2 from 7 to 1 | ||
362 | move 4 from 7 to 8 | ||
363 | move 3 from 8 to 6 | ||
364 | move 2 from 6 to 7 | ||
365 | move 6 from 7 to 8 | ||
366 | move 3 from 1 to 5 | ||
367 | move 4 from 5 to 9 | ||
368 | move 15 from 2 to 1 | ||
369 | move 4 from 6 to 4 | ||
370 | move 2 from 6 to 3 | ||
371 | move 1 from 3 to 7 | ||
372 | move 4 from 1 to 2 | ||
373 | move 1 from 3 to 4 | ||
374 | move 2 from 7 to 4 | ||
375 | move 5 from 9 to 3 | ||
376 | move 2 from 7 to 3 | ||
377 | move 16 from 4 to 8 | ||
378 | move 8 from 8 to 5 | ||
379 | move 2 from 1 to 5 | ||
380 | move 1 from 9 to 6 | ||
381 | move 1 from 6 to 5 | ||
382 | move 7 from 5 to 9 | ||
383 | move 3 from 1 to 8 | ||
384 | move 1 from 8 to 4 | ||
385 | move 8 from 2 to 7 | ||
386 | move 3 from 1 to 3 | ||
387 | move 1 from 3 to 9 | ||
388 | move 2 from 4 to 2 | ||
389 | move 7 from 8 to 5 | ||
390 | move 7 from 9 to 1 | ||
391 | move 6 from 3 to 5 | ||
392 | move 6 from 7 to 4 | ||
393 | move 3 from 4 to 1 | ||
394 | move 3 from 2 to 5 | ||
395 | move 1 from 7 to 8 | ||
396 | move 1 from 7 to 5 | ||
397 | move 1 from 9 to 8 | ||
398 | move 2 from 2 to 4 | ||
399 | move 15 from 1 to 6 | ||
400 | move 8 from 5 to 9 | ||
401 | move 3 from 3 to 4 | ||
402 | move 4 from 4 to 3 | ||
403 | move 1 from 9 to 7 | ||
404 | move 6 from 9 to 4 | ||
405 | move 1 from 9 to 2 | ||
406 | move 6 from 4 to 9 | ||
407 | move 2 from 4 to 6 | ||
408 | move 5 from 6 to 9 | ||
409 | move 1 from 3 to 1 | ||
410 | move 8 from 6 to 8 | ||
411 | move 12 from 5 to 3 | ||
412 | move 1 from 5 to 3 | ||
413 | move 1 from 3 to 8 | ||
414 | move 4 from 6 to 1 | ||
415 | move 11 from 3 to 8 | ||
416 | move 1 from 2 to 1 | ||
417 | move 23 from 8 to 2 | ||
418 | move 3 from 1 to 2 | ||
419 | move 1 from 1 to 9 | ||
420 | move 2 from 2 to 3 | ||
421 | move 6 from 3 to 6 | ||
422 | move 1 from 7 to 6 | ||
423 | move 1 from 4 to 7 | ||
424 | move 1 from 4 to 3 | ||
425 | move 1 from 7 to 3 | ||
426 | move 4 from 8 to 4 | ||
427 | move 2 from 1 to 8 | ||
428 | move 3 from 8 to 1 | ||
429 | move 4 from 6 to 2 | ||
430 | move 7 from 9 to 1 | ||
431 | move 1 from 9 to 6 | ||
432 | move 2 from 2 to 3 | ||
433 | move 3 from 9 to 4 | ||
434 | move 1 from 9 to 3 | ||
435 | move 10 from 2 to 8 | ||
436 | move 16 from 2 to 5 | ||
437 | move 2 from 3 to 6 | ||
438 | move 6 from 1 to 8 | ||
439 | move 1 from 1 to 5 | ||
440 | move 8 from 8 to 5 | ||
441 | move 11 from 5 to 9 | ||
442 | move 2 from 1 to 8 | ||
443 | move 1 from 1 to 8 | ||
444 | move 4 from 4 to 6 | ||
445 | move 3 from 3 to 9 | ||
446 | move 14 from 9 to 3 | ||
447 | move 15 from 8 to 5 | ||
448 | move 9 from 5 to 4 | ||
449 | move 7 from 6 to 1 | ||
450 | move 1 from 6 to 3 | ||
451 | move 4 from 4 to 7 | ||
452 | move 2 from 6 to 2 | ||
453 | move 4 from 7 to 4 | ||
454 | move 4 from 1 to 4 | ||
455 | move 10 from 4 to 3 | ||
456 | move 14 from 3 to 6 | ||
457 | move 5 from 4 to 1 | ||
458 | move 6 from 5 to 7 | ||
459 | move 1 from 2 to 6 | ||
460 | move 3 from 7 to 2 | ||
461 | move 2 from 2 to 3 | ||
462 | move 3 from 7 to 8 | ||
463 | move 2 from 8 to 2 | ||
464 | move 2 from 2 to 7 | ||
465 | move 6 from 6 to 2 | ||
466 | move 1 from 8 to 7 | ||
467 | move 8 from 2 to 7 | ||
468 | move 1 from 4 to 1 | ||
469 | move 5 from 5 to 3 | ||
470 | move 3 from 3 to 2 | ||
471 | move 5 from 1 to 3 | ||
472 | move 7 from 5 to 8 | ||
473 | move 6 from 6 to 3 | ||
474 | move 1 from 5 to 9 | ||
475 | move 10 from 7 to 9 | ||
476 | move 26 from 3 to 4 | ||
477 | move 1 from 5 to 1 | ||
478 | move 6 from 8 to 2 | ||
479 | move 9 from 2 to 9 | ||
480 | move 1 from 7 to 5 | ||
481 | move 1 from 8 to 5 | ||
482 | move 2 from 6 to 2 | ||
483 | move 20 from 9 to 6 | ||
484 | move 1 from 1 to 6 | ||
485 | move 1 from 4 to 2 | ||
486 | move 1 from 5 to 8 | ||
487 | move 1 from 5 to 7 | ||
488 | move 3 from 1 to 3 | ||
489 | move 1 from 3 to 6 | ||
490 | move 12 from 4 to 8 | ||
491 | move 11 from 4 to 5 | ||
492 | move 1 from 7 to 5 | ||
493 | move 1 from 2 to 8 | ||
494 | move 1 from 1 to 8 | ||
495 | move 2 from 2 to 5 | ||
496 | move 8 from 6 to 2 | ||
497 | move 5 from 6 to 4 | ||
498 | move 2 from 5 to 3 | ||
499 | move 12 from 8 to 4 | ||
500 | move 5 from 2 to 6 | ||
501 | move 3 from 8 to 1 | ||
502 | move 11 from 6 to 8 | ||
503 | move 10 from 4 to 6 | ||
504 | move 5 from 4 to 6 | ||
505 | move 12 from 6 to 5 | ||
506 | move 22 from 5 to 6 | ||
507 | move 3 from 6 to 5 | ||
508 | move 3 from 8 to 5 | ||
509 | move 1 from 3 to 8 | ||
510 | move 4 from 8 to 1 | ||
511 | move 6 from 1 to 7 | ||
512 | move 5 from 6 to 9 | ||
diff --git a/2022/day5/part1/Cargo.toml b/2022/day5/part1/Cargo.toml new file mode 100644 index 0000000..a479178 --- /dev/null +++ b/2022/day5/part1/Cargo.toml | |||
@@ -0,0 +1,10 @@ | |||
1 | [package] | ||
2 | name = "part1" | ||
3 | version = "0.1.0" | ||
4 | edition = "2021" | ||
5 | |||
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
7 | |||
8 | [dependencies] | ||
9 | itertools = "0.10.5" | ||
10 | regex = "1.7.0" | ||
diff --git a/2022/day5/part1/src/main.rs b/2022/day5/part1/src/main.rs new file mode 100644 index 0000000..f64fcce --- /dev/null +++ b/2022/day5/part1/src/main.rs | |||
@@ -0,0 +1,62 @@ | |||
1 | use itertools::Itertools; | ||
2 | use regex::Regex; | ||
3 | use std::collections::LinkedList; | ||
4 | |||
5 | fn main() { | ||
6 | let input: &str = include_str!("../../input"); | ||
7 | |||
8 | let width_finder = Regex::new(r"(?m)^\s1.*(\d)\s$").unwrap(); | ||
9 | let mut width = 0; | ||
10 | |||
11 | for cap in width_finder.captures_iter(input) { | ||
12 | width = str::parse(&cap[1]).unwrap(); | ||
13 | } | ||
14 | |||
15 | let mut crate_builder: Vec<LinkedList<char>> = Vec::new(); | ||
16 | |||
17 | for _ in 0..width { | ||
18 | crate_builder.push(LinkedList::new()); | ||
19 | } | ||
20 | |||
21 | for line in input.lines() { | ||
22 | let mut idx = 0; | ||
23 | if line.contains("1") { | ||
24 | break; | ||
25 | } | ||
26 | |||
27 | for part in &line.chars().chunks(4) { | ||
28 | let crt: String = part.collect(); | ||
29 | if !crt.contains("[") { | ||
30 | idx += 1; | ||
31 | } else { | ||
32 | let crate_ = crt.chars().nth(1).unwrap(); | ||
33 | crate_builder[idx].push_back(crate_); | ||
34 | idx += 1; | ||
35 | } | ||
36 | } | ||
37 | } | ||
38 | |||
39 | let move_parser = Regex::new(r"^move\s(\d+)\sfrom\s(\d)\sto\s(\d)").unwrap(); | ||
40 | |||
41 | for mv in input.lines().skip_while(|l| !l.contains("move")) { | ||
42 | for cap in move_parser.captures_iter(mv) { | ||
43 | let how_many = str::parse(&cap[1]).unwrap(); | ||
44 | let from: usize = str::parse(&cap[2]).unwrap(); | ||
45 | let to: usize = str::parse(&cap[3]).unwrap(); | ||
46 | |||
47 | for _ in 0..how_many { | ||
48 | if let Some(box_) = crate_builder[from - 1].pop_front() { | ||
49 | crate_builder[to - 1].push_front(box_); | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | |||
55 | println!( | ||
56 | "{}", | ||
57 | crate_builder | ||
58 | .iter() | ||
59 | .filter_map(|s| s.front()) | ||
60 | .collect::<String>() | ||
61 | ); | ||
62 | } | ||