diff options
author | Yigit Sever | 2021-12-10 19:54:01 +0300 |
---|---|---|
committer | Yigit Sever | 2021-12-10 19:54:01 +0300 |
commit | 3c97ec63d921c7d2f132a834f9b739cc8d039c99 (patch) | |
tree | 492bbff2312042c68e1a2d2d95ed0bf599dfe545 /2021 | |
parent | ae3853b6e8ab02023ccd74baac6dc177b1ee879a (diff) | |
download | aoc-3c97ec63d921c7d2f132a834f9b739cc8d039c99.tar.gz aoc-3c97ec63d921c7d2f132a834f9b739cc8d039c99.tar.bz2 aoc-3c97ec63d921c7d2f132a834f9b739cc8d039c99.zip |
2021, day3: done
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 |
4 files changed, 1119 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 | } | ||