diff options
Diffstat (limited to '2021')
-rw-r--r-- | 2021/day4/Cargo.toml | 8 | ||||
-rw-r--r-- | 2021/day4/input | 601 | ||||
-rw-r--r-- | 2021/day4/input.example | 19 | ||||
-rw-r--r-- | 2021/day4/src/main.rs | 99 |
4 files changed, 727 insertions, 0 deletions
diff --git a/2021/day4/Cargo.toml b/2021/day4/Cargo.toml new file mode 100644 index 0000000..8842130 --- /dev/null +++ b/2021/day4/Cargo.toml | |||
@@ -0,0 +1,8 @@ | |||
1 | [package] | ||
2 | name = "day4" | ||
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] | ||
diff --git a/2021/day4/input b/2021/day4/input new file mode 100644 index 0000000..33aa45f --- /dev/null +++ b/2021/day4/input | |||
@@ -0,0 +1,601 @@ | |||
1 | 84,28,29,75,58,71,26,6,73,74,41,39,87,37,16,79,55,60,62,80,64,95,46,15,5,47,2,35,32,78,89,90,96,33,4,69,42,30,54,85,65,83,44,63,20,17,66,81,67,77,36,68,82,93,10,25,9,34,24,72,91,88,11,38,3,45,14,56,22,61,97,27,12,48,18,1,31,98,86,19,99,92,8,43,52,23,21,0,7,50,57,70,49,13,51,40,76,94,53,59 | ||
2 | |||
3 | 31 93 46 11 30 | ||
4 | 2 45 40 69 33 | ||
5 | 82 21 37 99 86 | ||
6 | 57 16 34 94 85 | ||
7 | 60 49 28 14 65 | ||
8 | |||
9 | 96 2 20 41 24 | ||
10 | 29 15 27 83 48 | ||
11 | 7 93 99 82 26 | ||
12 | 3 91 66 35 85 | ||
13 | 62 78 67 4 22 | ||
14 | |||
15 | 10 87 50 84 40 | ||
16 | 78 5 17 59 44 | ||
17 | 38 88 15 46 32 | ||
18 | 8 72 74 90 23 | ||
19 | 64 93 49 39 20 | ||
20 | |||
21 | 25 41 32 30 39 | ||
22 | 6 66 38 95 5 | ||
23 | 31 13 56 67 34 | ||
24 | 69 18 64 44 96 | ||
25 | 75 14 88 97 40 | ||
26 | |||
27 | 39 62 50 10 68 | ||
28 | 18 7 95 72 82 | ||
29 | 83 23 19 70 71 | ||
30 | 11 64 30 8 3 | ||
31 | 6 81 27 34 99 | ||
32 | |||
33 | 40 52 66 20 49 | ||
34 | 93 74 16 35 29 | ||
35 | 97 88 6 98 81 | ||
36 | 62 55 99 47 12 | ||
37 | 83 76 57 75 22 | ||
38 | |||
39 | 52 76 43 86 99 | ||
40 | 58 26 61 36 42 | ||
41 | 11 69 65 3 49 | ||
42 | 33 7 71 8 25 | ||
43 | 50 82 32 16 64 | ||
44 | |||
45 | 45 38 88 96 8 | ||
46 | 22 17 5 60 66 | ||
47 | 87 12 61 59 2 | ||
48 | 0 37 18 15 98 | ||
49 | 7 62 23 56 92 | ||
50 | |||
51 | 20 7 12 26 69 | ||
52 | 81 63 89 57 19 | ||
53 | 18 44 61 64 53 | ||
54 | 47 27 8 30 0 | ||
55 | 60 99 28 6 96 | ||
56 | |||
57 | 70 50 63 56 26 | ||
58 | 55 97 65 5 96 | ||
59 | 72 68 29 91 61 | ||
60 | 34 0 14 28 4 | ||
61 | 45 53 78 80 47 | ||
62 | |||
63 | 19 12 92 80 97 | ||
64 | 22 37 38 9 82 | ||
65 | 86 72 99 59 89 | ||
66 | 73 18 21 87 46 | ||
67 | 33 77 71 54 94 | ||
68 | |||
69 | 66 99 10 44 48 | ||
70 | 38 45 4 63 62 | ||
71 | 50 27 88 56 89 | ||
72 | 81 91 72 90 32 | ||
73 | 76 29 17 6 7 | ||
74 | |||
75 | 71 39 10 77 50 | ||
76 | 97 95 90 98 4 | ||
77 | 66 32 73 35 16 | ||
78 | 1 99 7 96 23 | ||
79 | 74 31 94 37 5 | ||
80 | |||
81 | 20 72 78 5 69 | ||
82 | 88 8 55 80 30 | ||
83 | 62 58 4 53 47 | ||
84 | 45 13 7 14 52 | ||
85 | 86 12 66 74 76 | ||
86 | |||
87 | 95 53 59 68 37 | ||
88 | 63 40 20 46 43 | ||
89 | 5 27 67 84 39 | ||
90 | 99 51 12 76 50 | ||
91 | 78 23 89 22 57 | ||
92 | |||
93 | 0 96 2 88 11 | ||
94 | 98 52 70 28 22 | ||
95 | 60 50 18 49 41 | ||
96 | 97 6 68 21 47 | ||
97 | 90 57 58 99 48 | ||
98 | |||
99 | 7 3 77 61 34 | ||
100 | 57 69 64 68 58 | ||
101 | 8 49 33 22 15 | ||
102 | 63 10 4 95 59 | ||
103 | 28 20 71 44 75 | ||
104 | |||
105 | 90 68 15 99 38 | ||
106 | 16 80 56 70 3 | ||
107 | 88 52 18 4 39 | ||
108 | 40 85 89 84 44 | ||
109 | 65 73 71 79 2 | ||
110 | |||
111 | 66 43 12 10 70 | ||
112 | 79 57 54 41 6 | ||
113 | 46 73 40 3 52 | ||
114 | 36 21 38 8 62 | ||
115 | 7 26 42 32 0 | ||
116 | |||
117 | 57 51 69 34 43 | ||
118 | 14 9 96 88 74 | ||
119 | 90 22 83 30 71 | ||
120 | 80 64 91 48 97 | ||
121 | 54 38 89 66 16 | ||
122 | |||
123 | 51 4 49 2 59 | ||
124 | 53 40 33 54 45 | ||
125 | 69 41 92 26 60 | ||
126 | 93 72 94 90 35 | ||
127 | 76 8 75 38 52 | ||
128 | |||
129 | 5 75 19 28 39 | ||
130 | 14 80 27 64 78 | ||
131 | 24 69 23 96 42 | ||
132 | 0 81 10 20 13 | ||
133 | 36 57 17 76 52 | ||
134 | |||
135 | 38 25 7 88 33 | ||
136 | 24 41 96 85 64 | ||
137 | 52 89 63 93 18 | ||
138 | 94 20 0 98 28 | ||
139 | 9 30 27 79 83 | ||
140 | |||
141 | 74 97 15 55 67 | ||
142 | 92 28 24 11 38 | ||
143 | 8 70 65 63 45 | ||
144 | 83 22 30 76 96 | ||
145 | 21 85 29 59 36 | ||
146 | |||
147 | 1 79 29 0 75 | ||
148 | 68 58 61 84 51 | ||
149 | 85 74 46 69 3 | ||
150 | 94 16 41 43 15 | ||
151 | 57 21 48 22 42 | ||
152 | |||
153 | 61 5 1 25 28 | ||
154 | 50 40 74 14 94 | ||
155 | 32 0 68 15 54 | ||
156 | 60 45 51 31 97 | ||
157 | 56 52 8 9 63 | ||
158 | |||
159 | 20 36 72 74 83 | ||
160 | 4 88 35 62 24 | ||
161 | 68 39 58 30 34 | ||
162 | 61 41 42 93 66 | ||
163 | 48 12 57 6 11 | ||
164 | |||
165 | 89 52 47 66 64 | ||
166 | 67 28 30 46 22 | ||
167 | 44 79 23 86 80 | ||
168 | 81 25 10 53 94 | ||
169 | 56 87 74 60 75 | ||
170 | |||
171 | 38 62 76 43 50 | ||
172 | 83 53 64 4 44 | ||
173 | 52 47 91 49 7 | ||
174 | 0 85 96 78 86 | ||
175 | 32 8 81 87 90 | ||
176 | |||
177 | 76 67 31 74 87 | ||
178 | 15 70 9 83 78 | ||
179 | 60 46 86 73 72 | ||
180 | 71 53 82 89 28 | ||
181 | 39 97 68 96 11 | ||
182 | |||
183 | 88 7 32 40 94 | ||
184 | 39 68 13 6 9 | ||
185 | 20 55 72 49 25 | ||
186 | 56 86 78 12 18 | ||
187 | 27 34 19 48 44 | ||
188 | |||
189 | 88 19 29 87 28 | ||
190 | 53 47 40 74 77 | ||
191 | 3 93 14 38 33 | ||
192 | 78 39 26 32 22 | ||
193 | 75 0 2 95 54 | ||
194 | |||
195 | 52 35 43 77 79 | ||
196 | 53 56 93 92 12 | ||
197 | 15 23 16 10 66 | ||
198 | 63 96 58 60 94 | ||
199 | 6 55 76 21 89 | ||
200 | |||
201 | 55 11 26 37 18 | ||
202 | 77 80 0 30 58 | ||
203 | 2 97 13 27 98 | ||
204 | 68 40 91 56 20 | ||
205 | 78 42 45 87 24 | ||
206 | |||
207 | 62 71 79 12 66 | ||
208 | 9 73 30 70 88 | ||
209 | 18 72 27 5 75 | ||
210 | 49 3 47 33 6 | ||
211 | 55 63 98 15 21 | ||
212 | |||
213 | 20 52 46 33 27 | ||
214 | 80 2 48 29 62 | ||
215 | 9 32 5 41 53 | ||
216 | 74 39 87 12 73 | ||
217 | 96 79 61 63 22 | ||
218 | |||
219 | 30 48 26 21 83 | ||
220 | 56 94 39 47 99 | ||
221 | 93 66 25 76 57 | ||
222 | 60 96 62 13 84 | ||
223 | 71 42 28 31 20 | ||
224 | |||
225 | 30 77 49 36 34 | ||
226 | 53 75 11 38 61 | ||
227 | 41 72 4 58 92 | ||
228 | 91 10 21 51 31 | ||
229 | 89 43 14 23 45 | ||
230 | |||
231 | 30 76 12 1 21 | ||
232 | 31 0 82 2 8 | ||
233 | 26 28 61 32 99 | ||
234 | 65 46 16 39 74 | ||
235 | 60 63 5 50 42 | ||
236 | |||
237 | 31 90 72 81 8 | ||
238 | 17 94 45 20 38 | ||
239 | 30 28 68 0 25 | ||
240 | 84 10 37 61 83 | ||
241 | 87 70 32 64 99 | ||
242 | |||
243 | 21 28 99 30 2 | ||
244 | 86 64 53 54 84 | ||
245 | 82 13 79 96 55 | ||
246 | 76 3 12 92 98 | ||
247 | 27 89 10 37 95 | ||
248 | |||
249 | 74 38 98 18 55 | ||
250 | 62 82 93 85 46 | ||
251 | 43 3 26 84 86 | ||
252 | 97 1 19 12 67 | ||
253 | 94 72 68 88 0 | ||
254 | |||
255 | 41 97 88 0 40 | ||
256 | 20 5 51 42 87 | ||
257 | 38 9 11 50 6 | ||
258 | 35 25 54 12 81 | ||
259 | 75 58 57 94 26 | ||
260 | |||
261 | 2 30 22 48 88 | ||
262 | 60 86 69 31 57 | ||
263 | 97 58 95 47 71 | ||
264 | 85 63 81 80 73 | ||
265 | 25 92 62 11 83 | ||
266 | |||
267 | 3 93 20 74 86 | ||
268 | 21 31 73 35 91 | ||
269 | 41 28 25 4 92 | ||
270 | 19 5 38 52 59 | ||
271 | 37 16 48 85 68 | ||
272 | |||
273 | 26 32 66 93 68 | ||
274 | 74 90 70 41 57 | ||
275 | 99 94 51 3 46 | ||
276 | 1 24 17 54 39 | ||
277 | 53 60 50 96 49 | ||
278 | |||
279 | 50 27 72 42 84 | ||
280 | 82 62 39 33 31 | ||
281 | 99 4 20 3 70 | ||
282 | 11 28 57 55 12 | ||
283 | 61 29 14 60 90 | ||
284 | |||
285 | 60 23 66 99 3 | ||
286 | 6 24 42 51 45 | ||
287 | 41 39 53 25 72 | ||
288 | 32 57 5 74 4 | ||
289 | 78 44 67 7 50 | ||
290 | |||
291 | 8 39 4 42 50 | ||
292 | 27 25 77 94 90 | ||
293 | 52 45 59 60 84 | ||
294 | 0 78 36 86 22 | ||
295 | 56 1 71 82 29 | ||
296 | |||
297 | 78 11 49 67 93 | ||
298 | 99 76 12 37 1 | ||
299 | 17 35 19 92 91 | ||
300 | 22 54 31 72 36 | ||
301 | 61 96 63 26 33 | ||
302 | |||
303 | 1 69 71 21 72 | ||
304 | 87 92 32 29 80 | ||
305 | 40 39 52 42 75 | ||
306 | 26 24 11 44 23 | ||
307 | 10 99 62 36 98 | ||
308 | |||
309 | 60 47 49 24 66 | ||
310 | 2 19 38 57 94 | ||
311 | 54 22 17 33 42 | ||
312 | 65 80 48 86 20 | ||
313 | 53 27 59 30 11 | ||
314 | |||
315 | 3 81 64 69 82 | ||
316 | 93 80 71 51 46 | ||
317 | 76 7 38 57 91 | ||
318 | 37 88 8 65 54 | ||
319 | 36 25 1 95 77 | ||
320 | |||
321 | 75 56 19 21 34 | ||
322 | 15 7 24 41 86 | ||
323 | 68 29 85 80 88 | ||
324 | 18 58 81 44 62 | ||
325 | 0 52 89 47 59 | ||
326 | |||
327 | 49 98 57 90 46 | ||
328 | 76 88 84 60 6 | ||
329 | 38 78 77 83 99 | ||
330 | 79 48 5 63 74 | ||
331 | 66 30 37 4 47 | ||
332 | |||
333 | 56 37 93 43 11 | ||
334 | 81 87 85 52 94 | ||
335 | 64 91 36 97 27 | ||
336 | 18 31 26 22 78 | ||
337 | 50 54 32 69 96 | ||
338 | |||
339 | 73 20 51 50 30 | ||
340 | 48 83 22 76 85 | ||
341 | 26 3 63 67 92 | ||
342 | 97 0 87 88 1 | ||
343 | 18 33 86 77 52 | ||
344 | |||
345 | 1 18 50 7 22 | ||
346 | 11 96 47 94 67 | ||
347 | 58 36 43 65 6 | ||
348 | 91 53 23 34 44 | ||
349 | 81 30 83 86 55 | ||
350 | |||
351 | 1 36 10 84 90 | ||
352 | 55 35 74 23 26 | ||
353 | 29 53 76 40 85 | ||
354 | 89 77 16 17 93 | ||
355 | 11 19 65 5 49 | ||
356 | |||
357 | 99 48 88 10 79 | ||
358 | 84 75 66 74 58 | ||
359 | 3 26 92 91 86 | ||
360 | 87 98 52 45 21 | ||
361 | 56 51 0 85 69 | ||
362 | |||
363 | 53 45 75 5 82 | ||
364 | 44 90 11 2 85 | ||
365 | 69 19 46 89 47 | ||
366 | 4 22 16 84 52 | ||
367 | 81 1 39 9 38 | ||
368 | |||
369 | 18 57 15 30 35 | ||
370 | 9 32 52 44 25 | ||
371 | 69 43 61 3 51 | ||
372 | 2 8 80 85 33 | ||
373 | 72 13 45 10 87 | ||
374 | |||
375 | 52 24 26 74 49 | ||
376 | 0 37 61 91 54 | ||
377 | 70 96 60 80 39 | ||
378 | 11 75 85 46 18 | ||
379 | 16 90 20 66 67 | ||
380 | |||
381 | 13 74 92 11 7 | ||
382 | 59 46 41 12 55 | ||
383 | 27 77 89 70 96 | ||
384 | 81 5 29 32 51 | ||
385 | 84 75 33 63 99 | ||
386 | |||
387 | 87 58 84 6 68 | ||
388 | 65 9 75 48 90 | ||
389 | 41 94 89 64 21 | ||
390 | 95 81 72 32 30 | ||
391 | 83 17 63 52 97 | ||
392 | |||
393 | 89 0 61 92 16 | ||
394 | 44 65 25 66 20 | ||
395 | 29 27 37 94 68 | ||
396 | 10 63 12 48 77 | ||
397 | 6 32 82 4 40 | ||
398 | |||
399 | 1 20 69 80 45 | ||
400 | 8 7 15 27 19 | ||
401 | 40 87 2 98 32 | ||
402 | 35 79 84 71 14 | ||
403 | 24 43 23 29 6 | ||
404 | |||
405 | 59 62 32 74 58 | ||
406 | 78 61 85 4 75 | ||
407 | 40 30 24 31 46 | ||
408 | 89 39 23 63 37 | ||
409 | 45 29 44 21 19 | ||
410 | |||
411 | 88 44 39 81 43 | ||
412 | 26 18 10 73 3 | ||
413 | 62 63 74 53 60 | ||
414 | 0 65 84 54 21 | ||
415 | 14 25 76 13 2 | ||
416 | |||
417 | 61 57 77 0 92 | ||
418 | 12 27 68 89 72 | ||
419 | 86 21 44 43 40 | ||
420 | 41 74 26 73 66 | ||
421 | 9 59 32 3 8 | ||
422 | |||
423 | 20 93 99 67 28 | ||
424 | 53 52 19 72 23 | ||
425 | 31 65 25 88 10 | ||
426 | 61 37 43 9 76 | ||
427 | 60 33 87 3 96 | ||
428 | |||
429 | 83 15 46 70 80 | ||
430 | 90 69 1 6 64 | ||
431 | 43 33 17 99 53 | ||
432 | 98 25 30 8 31 | ||
433 | 66 94 13 12 75 | ||
434 | |||
435 | 18 52 83 3 19 | ||
436 | 41 51 60 13 54 | ||
437 | 33 5 69 99 8 | ||
438 | 27 44 31 34 4 | ||
439 | 17 25 1 68 79 | ||
440 | |||
441 | 92 23 93 26 75 | ||
442 | 50 28 30 42 25 | ||
443 | 77 83 56 95 34 | ||
444 | 57 13 27 65 81 | ||
445 | 7 71 40 94 9 | ||
446 | |||
447 | 16 28 3 39 82 | ||
448 | 7 99 44 69 8 | ||
449 | 49 51 93 34 6 | ||
450 | 60 84 0 92 2 | ||
451 | 76 88 38 68 24 | ||
452 | |||
453 | 23 99 47 36 77 | ||
454 | 20 90 4 78 93 | ||
455 | 71 88 52 28 92 | ||
456 | 97 31 25 95 39 | ||
457 | 6 21 68 45 53 | ||
458 | |||
459 | 0 51 69 75 56 | ||
460 | 10 47 12 52 6 | ||
461 | 65 87 77 85 42 | ||
462 | 98 23 25 97 30 | ||
463 | 84 86 67 35 22 | ||
464 | |||
465 | 24 36 70 99 98 | ||
466 | 94 1 59 67 35 | ||
467 | 81 25 6 61 68 | ||
468 | 72 53 9 40 92 | ||
469 | 97 73 91 41 10 | ||
470 | |||
471 | 1 78 3 66 15 | ||
472 | 39 29 24 76 98 | ||
473 | 10 25 90 30 55 | ||
474 | 41 96 83 72 51 | ||
475 | 46 87 42 26 44 | ||
476 | |||
477 | 20 60 59 4 21 | ||
478 | 50 71 45 31 1 | ||
479 | 49 75 37 54 28 | ||
480 | 84 46 98 24 2 | ||
481 | 96 16 51 79 35 | ||
482 | |||
483 | 59 46 65 39 95 | ||
484 | 92 5 10 63 36 | ||
485 | 16 90 56 89 70 | ||
486 | 83 45 24 64 74 | ||
487 | 55 27 54 2 51 | ||
488 | |||
489 | 16 23 63 62 57 | ||
490 | 17 26 58 83 60 | ||
491 | 39 68 22 98 48 | ||
492 | 65 50 76 3 14 | ||
493 | 24 75 25 7 86 | ||
494 | |||
495 | 35 26 74 81 56 | ||
496 | 62 84 34 30 33 | ||
497 | 5 73 21 15 93 | ||
498 | 78 77 69 49 43 | ||
499 | 44 11 54 51 87 | ||
500 | |||
501 | 56 78 74 24 39 | ||
502 | 70 85 6 84 9 | ||
503 | 97 65 16 82 5 | ||
504 | 2 12 20 79 42 | ||
505 | 14 37 15 69 26 | ||
506 | |||
507 | 42 31 88 46 71 | ||
508 | 65 97 11 34 48 | ||
509 | 85 96 27 0 7 | ||
510 | 41 9 5 72 53 | ||
511 | 37 93 98 57 64 | ||
512 | |||
513 | 1 10 55 57 99 | ||
514 | 61 92 82 86 56 | ||
515 | 19 16 43 84 87 | ||
516 | 42 6 79 46 17 | ||
517 | 51 44 64 73 35 | ||
518 | |||
519 | 17 0 84 15 34 | ||
520 | 57 92 41 82 40 | ||
521 | 8 38 16 35 4 | ||
522 | 6 33 79 97 96 | ||
523 | 52 11 21 10 73 | ||
524 | |||
525 | 89 2 81 22 34 | ||
526 | 77 87 84 11 80 | ||
527 | 85 67 96 49 40 | ||
528 | 19 3 76 98 16 | ||
529 | 29 1 20 35 82 | ||
530 | |||
531 | 4 57 84 91 6 | ||
532 | 8 16 69 1 0 | ||
533 | 73 2 41 20 5 | ||
534 | 98 40 96 82 93 | ||
535 | 12 51 23 68 83 | ||
536 | |||
537 | 64 52 50 1 94 | ||
538 | 97 58 24 90 5 | ||
539 | 9 75 3 61 37 | ||
540 | 84 91 34 29 8 | ||
541 | 30 74 4 18 45 | ||
542 | |||
543 | 92 63 96 34 9 | ||
544 | 14 25 89 4 98 | ||
545 | 23 67 90 74 77 | ||
546 | 61 3 93 55 82 | ||
547 | 51 65 48 36 8 | ||
548 | |||
549 | 70 65 20 76 50 | ||
550 | 17 1 33 15 22 | ||
551 | 3 98 44 91 55 | ||
552 | 59 83 2 67 87 | ||
553 | 14 63 56 86 37 | ||
554 | |||
555 | 61 53 45 88 36 | ||
556 | 96 74 15 39 42 | ||
557 | 32 55 44 46 86 | ||
558 | 79 94 27 54 57 | ||
559 | 65 3 21 17 75 | ||
560 | |||
561 | 14 26 18 54 20 | ||
562 | 24 22 90 0 16 | ||
563 | 70 28 33 12 27 | ||
564 | 45 95 30 65 75 | ||
565 | 19 81 39 2 84 | ||
566 | |||
567 | 48 23 67 75 86 | ||
568 | 40 46 87 27 93 | ||
569 | 79 44 13 3 53 | ||
570 | 24 98 54 34 8 | ||
571 | 49 1 39 28 35 | ||
572 | |||
573 | 3 29 16 5 80 | ||
574 | 86 50 6 45 88 | ||
575 | 22 71 73 34 94 | ||
576 | 81 28 68 20 30 | ||
577 | 33 37 95 35 57 | ||
578 | |||
579 | 49 1 6 26 30 | ||
580 | 56 5 63 79 15 | ||
581 | 34 52 87 19 66 | ||
582 | 59 96 80 42 58 | ||
583 | 50 32 72 38 74 | ||
584 | |||
585 | 83 90 18 23 64 | ||
586 | 87 89 62 31 66 | ||
587 | 81 49 9 8 56 | ||
588 | 51 85 63 32 50 | ||
589 | 95 47 11 98 17 | ||
590 | |||
591 | 68 83 80 25 48 | ||
592 | 72 39 7 20 30 | ||
593 | 32 38 12 66 64 | ||
594 | 29 10 44 23 45 | ||
595 | 58 15 91 81 95 | ||
596 | |||
597 | 90 67 30 22 58 | ||
598 | 35 50 63 59 19 | ||
599 | 54 4 41 38 65 | ||
600 | 43 47 56 96 20 | ||
601 | 87 57 33 37 49 | ||
diff --git a/2021/day4/input.example b/2021/day4/input.example new file mode 100644 index 0000000..669a51d --- /dev/null +++ b/2021/day4/input.example | |||
@@ -0,0 +1,19 @@ | |||
1 | 7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1 | ||
2 | |||
3 | 22 13 17 11 0 | ||
4 | 8 2 23 4 24 | ||
5 | 21 9 14 16 7 | ||
6 | 6 10 3 18 5 | ||
7 | 1 12 20 15 19 | ||
8 | |||
9 | 3 15 0 2 22 | ||
10 | 9 18 13 17 5 | ||
11 | 19 8 7 25 23 | ||
12 | 20 11 10 24 4 | ||
13 | 14 21 16 12 6 | ||
14 | |||
15 | 14 21 17 24 4 | ||
16 | 10 16 15 9 19 | ||
17 | 18 8 23 26 20 | ||
18 | 22 11 13 6 5 | ||
19 | 2 0 12 3 7 | ||
diff --git a/2021/day4/src/main.rs b/2021/day4/src/main.rs new file mode 100644 index 0000000..4b6150f --- /dev/null +++ b/2021/day4/src/main.rs | |||
@@ -0,0 +1,99 @@ | |||
1 | use std::env; | ||
2 | use std::fs::File; | ||
3 | use std::io::{BufRead, BufReader}; | ||
4 | |||
5 | fn main() { | ||
6 | let args: Vec<String> = env::args().collect(); | ||
7 | |||
8 | if args.len() != 2 { | ||
9 | eprintln!("Usage: {} filename", args[0]); | ||
10 | std::process::exit(1); | ||
11 | } | ||
12 | |||
13 | let filename = &args[1]; | ||
14 | |||
15 | let file = File::open(filename).unwrap_or_else(|_| panic!("No such file: {}", filename)); | ||
16 | let reader = BufReader::new(file); | ||
17 | |||
18 | let mut fd = reader.lines(); | ||
19 | let mut called_numbers: Vec<i32> = Vec::new(); | ||
20 | |||
21 | if let Ok(called_nums) = fd.next().unwrap() { | ||
22 | called_numbers = called_nums.split(",").map(|x| x.parse().unwrap()).collect(); | ||
23 | } | ||
24 | |||
25 | fd.next(); /* Skip the empty line */ | ||
26 | |||
27 | let mut boards: Vec<(Vec<(i32, bool)>, bool)> = Vec::new(); | ||
28 | |||
29 | 'outer: loop { | ||
30 | let mut miniboard: Vec<(i32, bool)> = Vec::new(); | ||
31 | for _ in 0..5 { | ||
32 | /* New Board */ | ||
33 | if let Some(maybe_line) = fd.next() { | ||
34 | if let Ok(line) = maybe_line { | ||
35 | for (a, b) in line | ||
36 | .split_whitespace() | ||
37 | .map(|x| x.parse().unwrap()) | ||
38 | .zip([false].iter().cycle()) | ||
39 | { | ||
40 | miniboard.push((a, *b)); | ||
41 | } | ||
42 | } | ||
43 | } else { | ||
44 | break 'outer; | ||
45 | } | ||
46 | } | ||
47 | boards.push((miniboard.clone(), false)); | ||
48 | fd.next(); /* Skip the empty line */ | ||
49 | } | ||
50 | |||
51 | for bingo in called_numbers { | ||
52 | for (board, _) in boards.iter_mut() { | ||
53 | for (num, mark) in board.iter_mut() { | ||
54 | if *num == bingo { | ||
55 | *mark = true; | ||
56 | } | ||
57 | } | ||
58 | } | ||
59 | |||
60 | let mut count; | ||
61 | for (board, won) in boards.iter_mut() { | ||
62 | for row in 0..5 { | ||
63 | count = 0; | ||
64 | for i in row * 5..(row * 5) + 5 { | ||
65 | if board[i].1 { | ||
66 | count += 1; | ||
67 | } | ||
68 | } | ||
69 | if count == 5 { | ||
70 | *won = true; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | for column in 0..5 { | ||
75 | count = 0; | ||
76 | for i in (0..5).map(|x| 5 * x + column) { | ||
77 | if board[i].1 { | ||
78 | count += 1; | ||
79 | } | ||
80 | } | ||
81 | if count == 5 { | ||
82 | *won = true; | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | if boards.len() == 1 { | ||
87 | let mut score: i32 = 0; | ||
88 | if let Some(board) = boards.get(0) { | ||
89 | for (winnynum, marked) in board.0.iter() { | ||
90 | if !marked { | ||
91 | score += winnynum; | ||
92 | } | ||
93 | } | ||
94 | println!("score: {}", score * bingo); | ||
95 | } | ||
96 | } | ||
97 | boards.retain(|x| !x.1); | ||
98 | } | ||
99 | } | ||