diff options
Diffstat (limited to '2021')
-rw-r--r-- | 2021/day3/Cargo.toml | 8 | ||||
-rw-r--r-- | 2021/day3/input | 1000 | ||||
-rw-r--r-- | 2021/day3/input.example | 12 | ||||
-rw-r--r-- | 2021/day3/src/main.rs | 99 | ||||
-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 |
8 files changed, 1846 insertions, 0 deletions
diff --git a/2021/day3/Cargo.toml b/2021/day3/Cargo.toml new file mode 100644 index 0000000..898e70d --- /dev/null +++ b/2021/day3/Cargo.toml | |||
@@ -0,0 +1,8 @@ | |||
1 | [package] | ||
2 | name = "day3" | ||
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/day3/input b/2021/day3/input new file mode 100644 index 0000000..929c455 --- /dev/null +++ b/2021/day3/input | |||
@@ -0,0 +1,1000 @@ | |||
1 | 010101110000 | ||
2 | 010011000110 | ||
3 | 010101000011 | ||
4 | 111100100001 | ||
5 | 011100110101 | ||
6 | 110001010101 | ||
7 | 001111110101 | ||
8 | 101100011100 | ||
9 | 010111111011 | ||
10 | 101010111101 | ||
11 | 101000001110 | ||
12 | 001000100001 | ||
13 | 000100011110 | ||
14 | 100011000100 | ||
15 | 101100100001 | ||
16 | 101010111010 | ||
17 | 111000001011 | ||
18 | 101101001011 | ||
19 | 000010010110 | ||
20 | 110111100111 | ||
21 | 111101011110 | ||
22 | 100100010010 | ||
23 | 110001011110 | ||
24 | 010011101000 | ||
25 | 111110000110 | ||
26 | 110001011111 | ||
27 | 001001010110 | ||
28 | 110111100100 | ||
29 | 100111000101 | ||
30 | 110011110000 | ||
31 | 000110000010 | ||
32 | 010001100001 | ||
33 | 111110111011 | ||
34 | 100010101011 | ||
35 | 000000010101 | ||
36 | 100010101110 | ||
37 | 100110100111 | ||
38 | 100111101111 | ||
39 | 110011110001 | ||
40 | 001000111100 | ||
41 | 001101010010 | ||
42 | 111101011101 | ||
43 | 011000110001 | ||
44 | 111111011010 | ||
45 | 011000000000 | ||
46 | 100000111001 | ||
47 | 011110101100 | ||
48 | 011101010111 | ||
49 | 011001111110 | ||
50 | 011100101101 | ||
51 | 101100010011 | ||
52 | 001100110000 | ||
53 | 110101101100 | ||
54 | 110110001100 | ||
55 | 000101101110 | ||
56 | 001010110010 | ||
57 | 111110110110 | ||
58 | 111010010011 | ||
59 | 100010111111 | ||
60 | 001001001000 | ||
61 | 110111001011 | ||
62 | 010110000010 | ||
63 | 100000000100 | ||
64 | 100001010010 | ||
65 | 110010011101 | ||
66 | 000001011011 | ||
67 | 000100010100 | ||
68 | 101011000001 | ||
69 | 011101110111 | ||
70 | 001100010100 | ||
71 | 101000010110 | ||
72 | 111111001100 | ||
73 | 110011001011 | ||
74 | 110000000000 | ||
75 | 010100110101 | ||
76 | 001111100011 | ||
77 | 100011010010 | ||
78 | 100111100011 | ||
79 | 110101001010 | ||
80 | 011111011000 | ||
81 | 001010100110 | ||
82 | 010101010100 | ||
83 | 110111011111 | ||
84 | 001001010000 | ||
85 | 001011010101 | ||
86 | 101111011011 | ||
87 | 101001101000 | ||
88 | 000011101110 | ||
89 | 000101110010 | ||
90 | 100011001010 | ||
91 | 011001010010 | ||
92 | 100100110011 | ||
93 | 010010011100 | ||
94 | 001100100110 | ||
95 | 100111110111 | ||
96 | 000111111000 | ||
97 | 100000001101 | ||
98 | 001111010101 | ||
99 | 000001001111 | ||
100 | 000101100000 | ||
101 | 000101001111 | ||
102 | 101010001001 | ||
103 | 111011110001 | ||
104 | 000111100011 | ||
105 | 110011000010 | ||
106 | 110011111101 | ||
107 | 101001010110 | ||
108 | 101111111000 | ||
109 | 000110100010 | ||
110 | 101111010001 | ||
111 | 010011110001 | ||
112 | 111110010010 | ||
113 | 101111011101 | ||
114 | 101110111101 | ||
115 | 010001011111 | ||
116 | 101110011010 | ||
117 | 001110001100 | ||
118 | 000110011001 | ||
119 | 000101000101 | ||
120 | 101010111011 | ||
121 | 110010101100 | ||
122 | 000100101101 | ||
123 | 010111011111 | ||
124 | 111001010110 | ||
125 | 000010100100 | ||
126 | 100000111100 | ||
127 | 101101110001 | ||
128 | 100001111010 | ||
129 | 000111010010 | ||
130 | 111100000110 | ||
131 | 010010000000 | ||
132 | 010001001011 | ||
133 | 111101010000 | ||
134 | 010011111110 | ||
135 | 111011101011 | ||
136 | 110110100110 | ||
137 | 100001000011 | ||
138 | 010010000110 | ||
139 | 010000000001 | ||
140 | 000001000101 | ||
141 | 011010100000 | ||
142 | 001011011000 | ||
143 | 110101010001 | ||
144 | 011000111110 | ||
145 | 010011101101 | ||
146 | 010011000011 | ||
147 | 011010011101 | ||
148 | 001101110100 | ||
149 | 010001100101 | ||
150 | 111011100011 | ||
151 | 010111101000 | ||
152 | 111100000010 | ||
153 | 010000110000 | ||
154 | 000100111001 | ||
155 | 010010110100 | ||
156 | 000101110110 | ||
157 | 000011001110 | ||
158 | 111010111100 | ||
159 | 100101010001 | ||
160 | 111011000101 | ||
161 | 011111101100 | ||
162 | 000110010001 | ||
163 | 100011101111 | ||
164 | 100101001110 | ||
165 | 101101110010 | ||
166 | 000000011010 | ||
167 | 000001101000 | ||
168 | 010110011000 | ||
169 | 110100001001 | ||
170 | 111111101100 | ||
171 | 011010110001 | ||
172 | 011100111101 | ||
173 | 001101010110 | ||
174 | 100111000111 | ||
175 | 000000001111 | ||
176 | 001110101010 | ||
177 | 101000011001 | ||
178 | 000111010111 | ||
179 | 100110110001 | ||
180 | 100011000011 | ||
181 | 110111101011 | ||
182 | 000110111001 | ||
183 | 000010010011 | ||
184 | 010111011001 | ||
185 | 000111001000 | ||
186 | 100011011010 | ||
187 | 011101000100 | ||
188 | 101010010100 | ||
189 | 010111110000 | ||
190 | 011011100111 | ||
191 | 000001110001 | ||
192 | 000100111000 | ||
193 | 111100001011 | ||
194 | 100101010000 | ||
195 | 000110110100 | ||
196 | 110011110111 | ||
197 | 111000010111 | ||
198 | 101110011000 | ||
199 | 110011010000 | ||
200 | 001111000100 | ||
201 | 111010001001 | ||
202 | 110001111000 | ||
203 | 011101011111 | ||
204 | 000001001100 | ||
205 | 110100111011 | ||
206 | 110001011011 | ||
207 | 001010000100 | ||
208 | 110011101110 | ||
209 | 101100100100 | ||
210 | 100101100001 | ||
211 | 001010001010 | ||
212 | 101010001000 | ||
213 | 000110101001 | ||
214 | 001100010000 | ||
215 | 110001000101 | ||
216 | 000100111110 | ||
217 | 000110100111 | ||
218 | 100010001010 | ||
219 | 100100010110 | ||
220 | 010001110011 | ||
221 | 101111010010 | ||
222 | 100000001001 | ||
223 | 000110110000 | ||
224 | 100010011011 | ||
225 | 111101000001 | ||
226 | 101111111011 | ||
227 | 111111100110 | ||
228 | 101001101010 | ||
229 | 000011111011 | ||
230 | 110000000011 | ||
231 | 000001111010 | ||
232 | 001001000100 | ||
233 | 101110001101 | ||
234 | 100111011111 | ||
235 | 110101101110 | ||
236 | 100011011011 | ||
237 | 101000010001 | ||
238 | 101001111000 | ||
239 | 111101110010 | ||
240 | 000101000011 | ||
241 | 100100010100 | ||
242 | 010101111101 | ||
243 | 100110001011 | ||
244 | 010011010111 | ||
245 | 110111100101 | ||
246 | 110010010101 | ||
247 | 100010101101 | ||
248 | 100110000110 | ||
249 | 001101000001 | ||
250 | 111001001000 | ||
251 | 010111010011 | ||
252 | 000110001111 | ||
253 | 010101011010 | ||
254 | 000000001000 | ||
255 | 001001100100 | ||
256 | 101111111001 | ||
257 | 001110101000 | ||
258 | 000110100100 | ||
259 | 001111101111 | ||
260 | 010100011000 | ||
261 | 010000110110 | ||
262 | 011101101110 | ||
263 | 010100100100 | ||
264 | 111110010101 | ||
265 | 101100000110 | ||
266 | 011010110000 | ||
267 | 001001011101 | ||
268 | 000000000101 | ||
269 | 100101111001 | ||
270 | 110101110110 | ||
271 | 100111101010 | ||
272 | 010010101101 | ||
273 | 010100001111 | ||
274 | 111111111110 | ||
275 | 011111000000 | ||
276 | 000001101111 | ||
277 | 011001011001 | ||
278 | 001101101000 | ||
279 | 011010110110 | ||
280 | 100101000110 | ||
281 | 110001101110 | ||
282 | 110100101011 | ||
283 | 010001110100 | ||
284 | 011110110101 | ||
285 | 010001010001 | ||
286 | 110110101000 | ||
287 | 010000100011 | ||
288 | 010101011001 | ||
289 | 101111111010 | ||
290 | 000011110010 | ||
291 | 001000011101 | ||
292 | 110001100010 | ||
293 | 110110000011 | ||
294 | 010000111011 | ||
295 | 111010010000 | ||
296 | 011001001000 | ||
297 | 000111011010 | ||
298 | 011111111100 | ||
299 | 111001111100 | ||
300 | 001101000100 | ||
301 | 101110001011 | ||
302 | 101110000111 | ||
303 | 011010111111 | ||
304 | 110011100111 | ||
305 | 001101110010 | ||
306 | 011111101111 | ||
307 | 001110000110 | ||
308 | 010111100001 | ||
309 | 110100101001 | ||
310 | 101010110010 | ||
311 | 111011010100 | ||
312 | 101001110010 | ||
313 | 101101000100 | ||
314 | 100111010001 | ||
315 | 000011010110 | ||
316 | 100110000100 | ||
317 | 101000101010 | ||
318 | 000000001010 | ||
319 | 110100111010 | ||
320 | 110010011010 | ||
321 | 100110010100 | ||
322 | 011101110010 | ||
323 | 000111111010 | ||
324 | 001000101001 | ||
325 | 110100110010 | ||
326 | 100100111011 | ||
327 | 011001010111 | ||
328 | 111000101010 | ||
329 | 011001011011 | ||
330 | 011010000000 | ||
331 | 001101101110 | ||
332 | 101010111000 | ||
333 | 101010011000 | ||
334 | 011000010101 | ||
335 | 111001011010 | ||
336 | 100111111111 | ||
337 | 001101001100 | ||
338 | 111011011010 | ||
339 | 110110100011 | ||
340 | 111010010100 | ||
341 | 000110011101 | ||
342 | 011100010011 | ||
343 | 011111100111 | ||
344 | 010110100000 | ||
345 | 001100001000 | ||
346 | 000110000110 | ||
347 | 000101011011 | ||
348 | 101011101011 | ||
349 | 111101111110 | ||
350 | 111111110000 | ||
351 | 101101001100 | ||
352 | 011000110110 | ||
353 | 100111001000 | ||
354 | 011011111100 | ||
355 | 001111011110 | ||
356 | 111011100100 | ||
357 | 000101010010 | ||
358 | 100011011000 | ||
359 | 100000100110 | ||
360 | 100000110011 | ||
361 | 011000010110 | ||
362 | 001010110100 | ||
363 | 100111100010 | ||
364 | 011110101011 | ||
365 | 110111111010 | ||
366 | 011100110110 | ||
367 | 100100000000 | ||
368 | 011010101101 | ||
369 | 001101000010 | ||
370 | 010110010111 | ||
371 | 100010011100 | ||
372 | 111101010101 | ||
373 | 011011010111 | ||
374 | 000000000110 | ||
375 | 101001100000 | ||
376 | 010100110011 | ||
377 | 010101111111 | ||
378 | 101110111001 | ||
379 | 101101111000 | ||
380 | 101110101000 | ||
381 | 011011111110 | ||
382 | 010001101010 | ||
383 | 001000101010 | ||
384 | 111100111111 | ||
385 | 001011011110 | ||
386 | 101010101001 | ||
387 | 011111001010 | ||
388 | 001001001111 | ||
389 | 101000101101 | ||
390 | 001111011000 | ||
391 | 000100001101 | ||
392 | 101101011000 | ||
393 | 001100000100 | ||
394 | 001000111101 | ||
395 | 000001110100 | ||
396 | 111101011111 | ||
397 | 111010000010 | ||
398 | 101111011111 | ||
399 | 001100110101 | ||
400 | 101010110001 | ||
401 | 001110111010 | ||
402 | 010010111110 | ||
403 | 101101010011 | ||
404 | 100001100110 | ||
405 | 110010010001 | ||
406 | 111100111001 | ||
407 | 000100010001 | ||
408 | 110010101010 | ||
409 | 111010110101 | ||
410 | 000001010110 | ||
411 | 000111110110 | ||
412 | 111010101100 | ||
413 | 011110001100 | ||
414 | 010110001001 | ||
415 | 010111100011 | ||
416 | 001010111000 | ||
417 | 100111100111 | ||
418 | 110110011001 | ||
419 | 010100000000 | ||
420 | 001011001111 | ||
421 | 110010110000 | ||
422 | 100011001111 | ||
423 | 100111111011 | ||
424 | 110001001001 | ||
425 | 000100101111 | ||
426 | 011010011011 | ||
427 | 001001111101 | ||
428 | 111110001100 | ||
429 | 101111110010 | ||
430 | 101100101110 | ||
431 | 100110111001 | ||
432 | 111010110011 | ||
433 | 110010011110 | ||
434 | 001111001101 | ||
435 | 010011100111 | ||
436 | 000111000011 | ||
437 | 101101000000 | ||
438 | 000001100101 | ||
439 | 011101111001 | ||
440 | 110100100110 | ||
441 | 000110000001 | ||
442 | 110111011101 | ||
443 | 011100000110 | ||
444 | 001011110100 | ||
445 | 010001011011 | ||
446 | 110000011110 | ||
447 | 110001001011 | ||
448 | 110100000001 | ||
449 | 011010010100 | ||
450 | 010010000101 | ||
451 | 001010110111 | ||
452 | 110001001111 | ||
453 | 101100000001 | ||
454 | 010000000000 | ||
455 | 101110010001 | ||
456 | 001100101110 | ||
457 | 010000011010 | ||
458 | 010100101011 | ||
459 | 011010101100 | ||
460 | 111101011011 | ||
461 | 110111010000 | ||
462 | 111111101111 | ||
463 | 111011111011 | ||
464 | 110001110111 | ||
465 | 011100100011 | ||
466 | 100001110101 | ||
467 | 100111011001 | ||
468 | 100110010000 | ||
469 | 100110101110 | ||
470 | 110101100001 | ||
471 | 001010001101 | ||
472 | 011101101000 | ||
473 | 110001001110 | ||
474 | 110010111011 | ||
475 | 111100110100 | ||
476 | 101011100011 | ||
477 | 010100100101 | ||
478 | 010001101111 | ||
479 | 111000110101 | ||
480 | 001000101011 | ||
481 | 101101000101 | ||
482 | 011000100111 | ||
483 | 001111000011 | ||
484 | 011000000011 | ||
485 | 000011001111 | ||
486 | 001010011111 | ||
487 | 101001100010 | ||
488 | 101010100001 | ||
489 | 001001110010 | ||
490 | 101010000111 | ||
491 | 010111011010 | ||
492 | 110101110111 | ||
493 | 000110101111 | ||
494 | 000110010011 | ||
495 | 010110110010 | ||
496 | 100111001011 | ||
497 | 001100111111 | ||
498 | 111110000001 | ||
499 | 110110111000 | ||
500 | 101010000100 | ||
501 | 011100101010 | ||
502 | 001000010101 | ||
503 | 010010011001 | ||
504 | 011111000110 | ||
505 | 010011010011 | ||
506 | 001011101101 | ||
507 | 001001110100 | ||
508 | 110101011100 | ||
509 | 011000110100 | ||
510 | 010101101000 | ||
511 | 100000100000 | ||
512 | 011011111010 | ||
513 | 011010011111 | ||
514 | 111011011101 | ||
515 | 001111101110 | ||
516 | 001000110101 | ||
517 | 010001011100 | ||
518 | 110101100010 | ||
519 | 001100100100 | ||
520 | 001100101011 | ||
521 | 100110111000 | ||
522 | 001100101101 | ||
523 | 101000001011 | ||
524 | 001100010101 | ||
525 | 001100011010 | ||
526 | 101011010101 | ||
527 | 110101011111 | ||
528 | 101111001011 | ||
529 | 000010001111 | ||
530 | 011110001111 | ||
531 | 110000000100 | ||
532 | 000110100001 | ||
533 | 010010101111 | ||
534 | 110000000110 | ||
535 | 010011000000 | ||
536 | 011001000101 | ||
537 | 001101011010 | ||
538 | 000011001101 | ||
539 | 110100101010 | ||
540 | 111001010111 | ||
541 | 010011010101 | ||
542 | 111010100101 | ||
543 | 111110110101 | ||
544 | 111110011100 | ||
545 | 110010000110 | ||
546 | 000110100011 | ||
547 | 001000111000 | ||
548 | 000101101100 | ||
549 | 101110001010 | ||
550 | 010010010110 | ||
551 | 100001110111 | ||
552 | 111010100010 | ||
553 | 110110010111 | ||
554 | 101000011000 | ||
555 | 100100111010 | ||
556 | 001000011011 | ||
557 | 111101101011 | ||
558 | 101001010111 | ||
559 | 100110000011 | ||
560 | 100001010001 | ||
561 | 011011000001 | ||
562 | 010110010101 | ||
563 | 110001010000 | ||
564 | 001110000000 | ||
565 | 111001001110 | ||
566 | 011011101100 | ||
567 | 000100001111 | ||
568 | 111000110011 | ||
569 | 111101101101 | ||
570 | 100110000000 | ||
571 | 100011110110 | ||
572 | 001000000010 | ||
573 | 110011011000 | ||
574 | 111000100110 | ||
575 | 100110110000 | ||
576 | 010011101010 | ||
577 | 111011001010 | ||
578 | 001101111000 | ||
579 | 001100000111 | ||
580 | 001110011110 | ||
581 | 100001000100 | ||
582 | 000010000111 | ||
583 | 011010101001 | ||
584 | 111110001001 | ||
585 | 110110000010 | ||
586 | 011011101101 | ||
587 | 110001111010 | ||
588 | 011001101110 | ||
589 | 010011000010 | ||
590 | 100101110100 | ||
591 | 101000100001 | ||
592 | 000111011101 | ||
593 | 101100001011 | ||
594 | 100000011010 | ||
595 | 111001001001 | ||
596 | 100000000001 | ||
597 | 000101111001 | ||
598 | 100101101101 | ||
599 | 111001101111 | ||
600 | 001011011011 | ||
601 | 000010101000 | ||
602 | 001010111010 | ||
603 | 000100100011 | ||
604 | 001110101101 | ||
605 | 100000111000 | ||
606 | 110110001110 | ||
607 | 000111101101 | ||
608 | 001010001111 | ||
609 | 011000111011 | ||
610 | 100000100100 | ||
611 | 100011010110 | ||
612 | 000010000000 | ||
613 | 001000001101 | ||
614 | 010001001110 | ||
615 | 000111111011 | ||
616 | 100110000001 | ||
617 | 110010111000 | ||
618 | 111100111100 | ||
619 | 001000001100 | ||
620 | 000010110100 | ||
621 | 011010001110 | ||
622 | 110001110101 | ||
623 | 001100000101 | ||
624 | 100010110100 | ||
625 | 111000000010 | ||
626 | 110100100101 | ||
627 | 010010111011 | ||
628 | 010110011001 | ||
629 | 001001101100 | ||
630 | 001010101010 | ||
631 | 100001011100 | ||
632 | 010001101001 | ||
633 | 000000010010 | ||
634 | 000101111010 | ||
635 | 011000101011 | ||
636 | 111111010101 | ||
637 | 011110101111 | ||
638 | 011110011001 | ||
639 | 001101101101 | ||
640 | 111110101110 | ||
641 | 101111110100 | ||
642 | 010101001111 | ||
643 | 010010011101 | ||
644 | 000110101100 | ||
645 | 011100000011 | ||
646 | 100011101001 | ||
647 | 101101100111 | ||
648 | 110011101100 | ||
649 | 000110111010 | ||
650 | 000011001000 | ||
651 | 111101010011 | ||
652 | 011011101110 | ||
653 | 111101001100 | ||
654 | 100100101111 | ||
655 | 111010110111 | ||
656 | 000001100110 | ||
657 | 110100110101 | ||
658 | 110100001011 | ||
659 | 111010000001 | ||
660 | 001011110011 | ||
661 | 001010110101 | ||
662 | 100001100000 | ||
663 | 101000101100 | ||
664 | 011011100001 | ||
665 | 000011011011 | ||
666 | 100101110001 | ||
667 | 101100111100 | ||
668 | 010000111110 | ||
669 | 010100101101 | ||
670 | 001111011111 | ||
671 | 110101010000 | ||
672 | 000110010100 | ||
673 | 001001011011 | ||
674 | 110111111011 | ||
675 | 111100010110 | ||
676 | 110000101011 | ||
677 | 111001000100 | ||
678 | 000100000111 | ||
679 | 001011001110 | ||
680 | 011110100010 | ||
681 | 011011110101 | ||
682 | 001100011001 | ||
683 | 111010011111 | ||
684 | 011011110110 | ||
685 | 111101000000 | ||
686 | 101111110000 | ||
687 | 011100111000 | ||
688 | 010010011011 | ||
689 | 101000110010 | ||
690 | 001101101111 | ||
691 | 010001000011 | ||
692 | 001010010110 | ||
693 | 101000010010 | ||
694 | 110111001111 | ||
695 | 011111010101 | ||
696 | 111111011001 | ||
697 | 100011110011 | ||
698 | 110001100100 | ||
699 | 100000010100 | ||
700 | 001111011010 | ||
701 | 111001111000 | ||
702 | 110101001011 | ||
703 | 101000110001 | ||
704 | 111001111111 | ||
705 | 110000010111 | ||
706 | 000000100100 | ||
707 | 101011101110 | ||
708 | 111001110111 | ||
709 | 001110011010 | ||
710 | 110011101000 | ||
711 | 001011100100 | ||
712 | 011001011111 | ||
713 | 010100010101 | ||
714 | 011111111010 | ||
715 | 010010110000 | ||
716 | 100011101110 | ||
717 | 000011000110 | ||
718 | 001001010111 | ||
719 | 010111110100 | ||
720 | 010110110101 | ||
721 | 010000101000 | ||
722 | 101010101010 | ||
723 | 000100100010 | ||
724 | 000110011000 | ||
725 | 101010110101 | ||
726 | 100000100001 | ||
727 | 101100010010 | ||
728 | 010110000110 | ||
729 | 011011010011 | ||
730 | 000001010010 | ||
731 | 011101111110 | ||
732 | 100010000100 | ||
733 | 000100101110 | ||
734 | 010110010001 | ||
735 | 101100011011 | ||
736 | 010111010000 | ||
737 | 101100011111 | ||
738 | 010011001010 | ||
739 | 100010100000 | ||
740 | 001001101001 | ||
741 | 110010011001 | ||
742 | 111000110100 | ||
743 | 111111010000 | ||
744 | 111100101110 | ||
745 | 101010001010 | ||
746 | 111111100100 | ||
747 | 011110001110 | ||
748 | 101100001111 | ||
749 | 001010001100 | ||
750 | 110100100011 | ||
751 | 011100010101 | ||
752 | 110001011000 | ||
753 | 000010100001 | ||
754 | 011000011110 | ||
755 | 000000101101 | ||
756 | 000011101101 | ||
757 | 111010011000 | ||
758 | 000101110100 | ||
759 | 111100011010 | ||
760 | 101100010110 | ||
761 | 100001101011 | ||
762 | 110100110100 | ||
763 | 101100111010 | ||
764 | 010000011110 | ||
765 | 101001100011 | ||
766 | 000101110001 | ||
767 | 001101111111 | ||
768 | 111101000101 | ||
769 | 100101111101 | ||
770 | 001101011110 | ||
771 | 011111101011 | ||
772 | 100000010101 | ||
773 | 011010000001 | ||
774 | 011000011101 | ||
775 | 110101011110 | ||
776 | 111010101000 | ||
777 | 110111111100 | ||
778 | 101111110011 | ||
779 | 101101001001 | ||
780 | 000111101001 | ||
781 | 010110000011 | ||
782 | 110011000000 | ||
783 | 000001111101 | ||
784 | 001011101000 | ||
785 | 001001111011 | ||
786 | 110110000111 | ||
787 | 101100010101 | ||
788 | 101100100111 | ||
789 | 000010110001 | ||
790 | 110000111011 | ||
791 | 110111001000 | ||
792 | 010010111111 | ||
793 | 100010110000 | ||
794 | 010000111100 | ||
795 | 101001000111 | ||
796 | 010100001100 | ||
797 | 001111001010 | ||
798 | 010100101010 | ||
799 | 100001000010 | ||
800 | 010011101111 | ||
801 | 100011000001 | ||
802 | 110000001101 | ||
803 | 011001011110 | ||
804 | 100111111001 | ||
805 | 001100111101 | ||
806 | 010110100110 | ||
807 | 001000011001 | ||
808 | 101000111110 | ||
809 | 000100001011 | ||
810 | 111110100111 | ||
811 | 011100111001 | ||
812 | 100011111001 | ||
813 | 100001100001 | ||
814 | 110110001011 | ||
815 | 110011101111 | ||
816 | 011010111011 | ||
817 | 110101010110 | ||
818 | 010111101001 | ||
819 | 111110000011 | ||
820 | 111100000111 | ||
821 | 011111100100 | ||
822 | 101001000001 | ||
823 | 110111010100 | ||
824 | 000011000000 | ||
825 | 000100111101 | ||
826 | 001100010011 | ||
827 | 100000010011 | ||
828 | 010010001001 | ||
829 | 010111000100 | ||
830 | 110110010100 | ||
831 | 011100101110 | ||
832 | 110110100010 | ||
833 | 100111010111 | ||
834 | 001111010011 | ||
835 | 000110110110 | ||
836 | 000010000110 | ||
837 | 110100010001 | ||
838 | 010100111101 | ||
839 | 011001000110 | ||
840 | 101011010100 | ||
841 | 001110001101 | ||
842 | 101111110101 | ||
843 | 110011001010 | ||
844 | 110100011100 | ||
845 | 001101011000 | ||
846 | 100101101110 | ||
847 | 000001000111 | ||
848 | 111001101011 | ||
849 | 101011000010 | ||
850 | 001001011111 | ||
851 | 111000111010 | ||
852 | 111011100110 | ||
853 | 001001011100 | ||
854 | 000010011000 | ||
855 | 000101001001 | ||
856 | 100110001111 | ||
857 | 010100100010 | ||
858 | 001101000101 | ||
859 | 010111111100 | ||
860 | 100010000001 | ||
861 | 110101101111 | ||
862 | 100010101010 | ||
863 | 110110010001 | ||
864 | 011101000111 | ||
865 | 011110001010 | ||
866 | 100110011110 | ||
867 | 010011100100 | ||
868 | 110101110100 | ||
869 | 000000110010 | ||
870 | 001111101100 | ||
871 | 010011010010 | ||
872 | 010000100000 | ||
873 | 110001000100 | ||
874 | 110110111111 | ||
875 | 011100001111 | ||
876 | 110110001101 | ||
877 | 111110000010 | ||
878 | 010001110010 | ||
879 | 001101110101 | ||
880 | 111111101101 | ||
881 | 010101101101 | ||
882 | 001011011100 | ||
883 | 001011000001 | ||
884 | 001011011101 | ||
885 | 010001100010 | ||
886 | 011110110011 | ||
887 | 000101101011 | ||
888 | 000110111000 | ||
889 | 101101110000 | ||
890 | 101011011001 | ||
891 | 001001001110 | ||
892 | 000001000000 | ||
893 | 101011010010 | ||
894 | 101110010111 | ||
895 | 110011100001 | ||
896 | 001011101001 | ||
897 | 000000100001 | ||
898 | 010000100110 | ||
899 | 101111010000 | ||
900 | 011000011100 | ||
901 | 100011100110 | ||
902 | 110111110011 | ||
903 | 110010000100 | ||
904 | 101110000000 | ||
905 | 110010101101 | ||
906 | 011101111000 | ||
907 | 001111000110 | ||
908 | 101001011100 | ||
909 | 011111001111 | ||
910 | 111011101010 | ||
911 | 001110101110 | ||
912 | 101001000011 | ||
913 | 111101101111 | ||
914 | 111001110101 | ||
915 | 000110100110 | ||
916 | 111111011011 | ||
917 | 101011011011 | ||
918 | 111100101101 | ||
919 | 111111010100 | ||
920 | 101010010000 | ||
921 | 101000110011 | ||
922 | 011110100000 | ||
923 | 010100101001 | ||
924 | 010011100011 | ||
925 | 101000111001 | ||
926 | 101100000111 | ||
927 | 101010100010 | ||
928 | 101110011111 | ||
929 | 111011011110 | ||
930 | 110011011001 | ||
931 | 101001101101 | ||
932 | 110010001011 | ||
933 | 010100101000 | ||
934 | 001010011010 | ||
935 | 001100000000 | ||
936 | 110000010000 | ||
937 | 000110111011 | ||
938 | 011101111111 | ||
939 | 011001001001 | ||
940 | 011011001001 | ||
941 | 000100101001 | ||
942 | 110010010010 | ||
943 | 000110001001 | ||
944 | 001000100011 | ||
945 | 101011101111 | ||
946 | 100111110010 | ||
947 | 110010101011 | ||
948 | 000000110110 | ||
949 | 010111001101 | ||
950 | 100100001111 | ||
951 | 100010001011 | ||
952 | 011101100100 | ||
953 | 000011111000 | ||
954 | 010100111011 | ||
955 | 010101101100 | ||
956 | 100110100110 | ||
957 | 110100101110 | ||
958 | 010111111001 | ||
959 | 010010011110 | ||
960 | 111110000100 | ||
961 | 000110001101 | ||
962 | 100100100001 | ||
963 | 111011010111 | ||
964 | 101001010101 | ||
965 | 111011010010 | ||
966 | 101001000000 | ||
967 | 100111101100 | ||
968 | 101010110000 | ||
969 | 000111001101 | ||
970 | 000100100110 | ||
971 | 100100101000 | ||
972 | 111000011001 | ||
973 | 000110110101 | ||
974 | 111010000011 | ||
975 | 101100110001 | ||
976 | 000001011000 | ||
977 | 001110110011 | ||
978 | 101000100110 | ||
979 | 100110100101 | ||
980 | 010001000111 | ||
981 | 100011010001 | ||
982 | 010100011101 | ||
983 | 110100110110 | ||
984 | 100010100110 | ||
985 | 101100010001 | ||
986 | 010011000100 | ||
987 | 100100010101 | ||
988 | 110000101101 | ||
989 | 010101001100 | ||
990 | 100011100100 | ||
991 | 001111010100 | ||
992 | 100111001001 | ||
993 | 110000100000 | ||
994 | 100100010111 | ||
995 | 010101000010 | ||
996 | 101101001010 | ||
997 | 110101111101 | ||
998 | 010100000110 | ||
999 | 011101100110 | ||
1000 | 011011010010 | ||
diff --git a/2021/day3/input.example b/2021/day3/input.example new file mode 100644 index 0000000..a6366a8 --- /dev/null +++ b/2021/day3/input.example | |||
@@ -0,0 +1,12 @@ | |||
1 | 00100 | ||
2 | 11110 | ||
3 | 10110 | ||
4 | 10111 | ||
5 | 10101 | ||
6 | 01111 | ||
7 | 00111 | ||
8 | 11100 | ||
9 | 10000 | ||
10 | 11001 | ||
11 | 00010 | ||
12 | 01010 | ||
diff --git a/2021/day3/src/main.rs b/2021/day3/src/main.rs new file mode 100644 index 0000000..2440a39 --- /dev/null +++ b/2021/day3/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 numbers: Vec<u32> = Vec::new(); | ||
19 | |||
20 | for line in reader.lines() { | ||
21 | let line = line.unwrap(); | ||
22 | numbers.push(isize::from_str_radix(&line, 2).unwrap().try_into().unwrap()); | ||
23 | } | ||
24 | |||
25 | let mut co2_numbers: Vec<u32> = numbers.clone(); | ||
26 | let mut oxygen: u32 = 0; | ||
27 | let mut co2: u32 = 0; | ||
28 | |||
29 | for bit in (0..12).rev() { | ||
30 | let keep; | ||
31 | let mut one_bits = 0; | ||
32 | let mut zero_bits = 0; | ||
33 | for num in &numbers { | ||
34 | one_bits += (num >> bit) & 1; | ||
35 | zero_bits += ((num >> bit) & 1) ^ 1; | ||
36 | } | ||
37 | |||
38 | println!("for bit: {}", bit); | ||
39 | println!("one_bits: {}", one_bits); | ||
40 | println!("zero_bits: {}", zero_bits); | ||
41 | |||
42 | if zero_bits > one_bits { | ||
43 | keep = 0; | ||
44 | } else if zero_bits < one_bits { | ||
45 | keep = 1; | ||
46 | } else { | ||
47 | keep = 1; | ||
48 | } | ||
49 | |||
50 | println!("keeping {}", keep); | ||
51 | |||
52 | numbers.retain(|num| ((num >> bit) & 1) == keep); | ||
53 | |||
54 | if numbers.len() == 1 { | ||
55 | oxygen = numbers.pop().unwrap(); | ||
56 | break; | ||
57 | } | ||
58 | |||
59 | println!("{:?}", numbers); | ||
60 | } | ||
61 | |||
62 | println!("====co2 now===="); | ||
63 | |||
64 | for bit in (0..12).rev() { | ||
65 | let keep; | ||
66 | let mut one_bits = 0; | ||
67 | let mut zero_bits = 0; | ||
68 | for num in &co2_numbers { | ||
69 | one_bits += (num >> bit) & 1; | ||
70 | zero_bits += ((num >> bit) & 1) ^ 1; | ||
71 | } | ||
72 | |||
73 | println!("for bit: {}", bit); | ||
74 | println!("one_bits: {}", one_bits); | ||
75 | println!("zero_bits: {}", zero_bits); | ||
76 | |||
77 | if zero_bits > one_bits { | ||
78 | keep = 1; | ||
79 | } else if zero_bits < one_bits { | ||
80 | keep = 0; | ||
81 | } else { | ||
82 | keep = 0; | ||
83 | } | ||
84 | |||
85 | println!("keeping {}", keep); | ||
86 | |||
87 | co2_numbers.retain(|num| (num >> bit) & 1 == keep); | ||
88 | |||
89 | if co2_numbers.len() == 1 { | ||
90 | co2 = co2_numbers.pop().unwrap(); | ||
91 | break; | ||
92 | } | ||
93 | |||
94 | println!("{:?}", co2_numbers); | ||
95 | } | ||
96 | |||
97 | println!("oxygen: {}\nco2: {}", oxygen, co2); | ||
98 | println!("answer: {}", oxygen * co2); | ||
99 | } | ||
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 | } | ||