Compare commits
No commits in common. "f78ab44ab2d41608639c3f758ecbaf7571d5f20c" and "4dba9ee6bf0cc2a131f0cd654ad3acc444f1d168" have entirely different histories.
f78ab44ab2
...
4dba9ee6bf
|
@ -4,5 +4,4 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
colored="2.1.0"
|
|
||||||
regex="1.11.1"
|
regex="1.11.1"
|
||||||
|
|
850
inputs/07.txt
850
inputs/07.txt
|
@ -1,850 +0,0 @@
|
||||||
20261572812: 98 138 31 2 666
|
|
||||||
45327: 8 9 335 97 87
|
|
||||||
829287: 99 13 816 7 1 744 9
|
|
||||||
231630061: 460 2 33 93 500 1 52 8
|
|
||||||
651017: 713 52 851
|
|
||||||
30996182: 4 107 24 60 50 60 182
|
|
||||||
16545464: 810 5 1 85 3 6 4 6 19
|
|
||||||
146327: 7 4 8 7 7 1 1 3 73 466 7
|
|
||||||
326: 6 4 5 7 91 4 62 8 85 7 3 9
|
|
||||||
14687269: 7 63 8 5 6 337 1 857 1 3
|
|
||||||
1730: 82 7 613 522 21
|
|
||||||
6511850: 626 2 36 4 1 8 9 9 1 665
|
|
||||||
13883777: 43 3 923 109 3 1 1 11
|
|
||||||
19083747060: 546 3 33 44 5 5 38 3 6 7
|
|
||||||
1568: 84 9 71 662 6 63 9 1
|
|
||||||
203: 72 48 4 70 9
|
|
||||||
157: 70 83 4
|
|
||||||
1494863426: 249 6 2 4 2 748 9 4 3 4
|
|
||||||
416767: 392 19 52 90 9 55
|
|
||||||
60088: 8 1 2 723 12 67
|
|
||||||
3169: 25 98 3 685 31
|
|
||||||
11301912270: 2 680 336 4 5 6 9 5 274
|
|
||||||
2292: 29 418 11 5 2
|
|
||||||
48651: 40 304 4 5 6
|
|
||||||
33745743: 49 3 9 890 9 1 846 9
|
|
||||||
867714120: 374 4 6 5 327 234
|
|
||||||
26733890742: 8 95 2 8 4 729 45 6 1 6
|
|
||||||
4511655425: 11 59 4 94 613 3 64
|
|
||||||
44441: 92 524 72 81 7 1
|
|
||||||
7991: 6 5 9 1 764 7 7 5 733 1
|
|
||||||
278337: 8 7 248 8 4 5 375 6 30 6
|
|
||||||
476229876539: 94 3 1 9 8 9 29 9 1 5 7 39
|
|
||||||
1733207525: 13 2 525 3 19 6 301 25
|
|
||||||
1466117: 8 17 9 509 846
|
|
||||||
1189: 4 5 5 3 889
|
|
||||||
7817084617971: 781 708 4 570 47 9 72
|
|
||||||
151614: 16 4 3 5 92
|
|
||||||
8682: 2 8 86 3 24
|
|
||||||
7446697: 35 71 38 7 97
|
|
||||||
8668844903: 2 5 276 5 3 8 1 2 6 71 8 3
|
|
||||||
22949069796: 2 815 9 8 9 7 6 73 6 8 9 4
|
|
||||||
73257040: 4 54 1 3 9 7 7 6 21 3 7
|
|
||||||
2434621: 629 289 34 1 78 85
|
|
||||||
135: 20 7 5
|
|
||||||
213408: 1 369 86 234 2
|
|
||||||
106817943544: 2 74 29 852 61 50 14 4
|
|
||||||
50897732: 53 4 3 2 8 98 66 5 15 74
|
|
||||||
481687: 63 545 18 44 151
|
|
||||||
866107837: 68 962 5 662 4
|
|
||||||
21651: 1 7 4 3 6 5 2 5
|
|
||||||
1867497: 33 5 629 3 784 6
|
|
||||||
658564: 2 6 4 6 53 42 4 4 4 2 2
|
|
||||||
1286: 6 327 878 70 5
|
|
||||||
150654: 7 53 20 2 52
|
|
||||||
32009509009: 619 108 3 6 29 95 7 4 9
|
|
||||||
128298588: 8 2 5 77 4 8 9 8 65 2 8 12
|
|
||||||
106971480: 1 6 7 23 5 88 6 7 4 85 99
|
|
||||||
1298: 838 4 118 5 333
|
|
||||||
109869: 30 95 499 68 4 3
|
|
||||||
9534854: 9 47 9 1 5 628 449 36 1
|
|
||||||
16008: 295 7 1 948 105 884 4
|
|
||||||
7800300697: 60 9 37 8 450 231 3 4
|
|
||||||
19656: 93 6 4 53 42 3
|
|
||||||
3331320: 17 7 6 124 80 744 85 3
|
|
||||||
2023999391: 681 118 4 7 7 4 514
|
|
||||||
239993784: 7 41 2 5 527 191 7 948
|
|
||||||
769876: 4 6 6 285 8 5 9 1 1 5 9 1
|
|
||||||
730784: 545 6 6 41 32
|
|
||||||
94876096665: 24 2 7 20 1 6 1 7 4 2 665
|
|
||||||
459334762: 2 2 9 93 2 3 8 9 412 8 2
|
|
||||||
6027067800: 3 27 695 221 120
|
|
||||||
42749: 4 7 399 44 5
|
|
||||||
137175: 84 9 59 25
|
|
||||||
16830002448: 337 6 2 9 3 7 8 17 6 477
|
|
||||||
473075680: 453 64 172 76 70
|
|
||||||
950398: 63 8 119 5 398
|
|
||||||
3374757296819: 721 4 4 9 71 514 130
|
|
||||||
8906411904: 43 834 398 20 624
|
|
||||||
89494: 6 2 451 8 9 634 3 1 6 7 6
|
|
||||||
385612430: 10 7 677 103 79
|
|
||||||
226663: 1 7 5 11 280 2 2 1 5 69
|
|
||||||
7019457032: 2 83 3 809 1 41 826
|
|
||||||
117829733: 332 846 297 22 6 4 1
|
|
||||||
4293: 47 5 61 8 4 576 92 9
|
|
||||||
27956: 4 3 50 13 6
|
|
||||||
1698430: 2 4 737 4 72 226 156
|
|
||||||
904: 46 9 2 654 52 20 68
|
|
||||||
592947912: 1 219 8 5 903 8 3 83 8 3
|
|
||||||
594519: 59 1 4 51 9
|
|
||||||
82300: 7 2 113 64 50
|
|
||||||
18655560: 3 365 66 1 84
|
|
||||||
183864: 4 9 80 95 978
|
|
||||||
4549914: 4 6 46 9 1 582 8 4 952 9
|
|
||||||
627883: 6 278 8 3
|
|
||||||
18928824: 3 5 6 262 81 4 2 24
|
|
||||||
57994: 1 4 95 2 15 73 2 1 31
|
|
||||||
1759022: 39 1 8 5 42 8 493
|
|
||||||
5033908: 23 706 3 31 35
|
|
||||||
556387631: 7 7 54 90 3 6 67 6 3 32
|
|
||||||
1458452: 2 3 1 4 90 158 678 9 4
|
|
||||||
746735089: 45 775 519 2 67 91 3 9
|
|
||||||
96495380: 4 85 303 17 6 1 4 149
|
|
||||||
275290785: 1 5 3 8 42 4 5 505 4 6 5 9
|
|
||||||
9455765: 424 946 4 69 4
|
|
||||||
603870572: 903 86 6 6 6 9 491 2 2
|
|
||||||
2110: 51 114 91 8 62
|
|
||||||
2463: 3 303 756 2 3 1 791 1
|
|
||||||
65915810695: 65 827 88 810 696
|
|
||||||
185882150: 1 8 58 821 47
|
|
||||||
95795337: 86 254 617 953 37
|
|
||||||
159378123309: 8 9 7 6 1 520 82 20 5 3 3
|
|
||||||
480856880: 9 7 73 6 670 3 8 1 6 4 8 7
|
|
||||||
2592: 75 176 8 5
|
|
||||||
123664181: 1 8 391 8 4 644 6 2 723
|
|
||||||
29321568: 834 366 189 96 1
|
|
||||||
195388: 903 36 6 277 63
|
|
||||||
4824530231: 15 75 7 497 36 30 231
|
|
||||||
33868: 5 3 78 4 5 6 1 53 1
|
|
||||||
734046: 81 65 44 15 114
|
|
||||||
14871045810: 619 6 4 2 1 148 45 81 1
|
|
||||||
3448940: 774 88 4 931 9
|
|
||||||
48501274: 61 5 67 9 5 6 9 45 88 6
|
|
||||||
7122124803: 6 105 8 92 16 480 2 3
|
|
||||||
56015: 62 14 9 9 7
|
|
||||||
63596840304: 3 3 91 27 92 5 15 2 2
|
|
||||||
17858156412: 7 3 49 450 9 7 540 9 3
|
|
||||||
390165: 6 3 8 22 316 6 2 4 9 37
|
|
||||||
1276750: 50 6 51 1 8 28 9 98 4 6
|
|
||||||
9471132: 816 67 2 3 633 3 132
|
|
||||||
5998115: 51 4 4 9 6 816 515
|
|
||||||
405042823: 54 75 42 823
|
|
||||||
270329888710: 6 3 38 9 5 8 8 72 4 7 10
|
|
||||||
9011938: 5 3 5 1 7 36 36 3 7 9 3 20
|
|
||||||
660: 4 75 581
|
|
||||||
1341831680: 4 7 258 141 88 56 560
|
|
||||||
22831300800: 7 4 876 5 591 80 7 5 9
|
|
||||||
6298914: 5 113 64 8 914
|
|
||||||
29294: 3 9 76 876 2 11
|
|
||||||
237239168: 35 7 1 8 2 828 85 7 67 1
|
|
||||||
1802251877126: 15 2 267 25 2 9 77 129
|
|
||||||
11008: 4 865 554 2 96 74
|
|
||||||
642251445: 64 22 5 144 5
|
|
||||||
2064: 3 2 78 543 7 9 5 2
|
|
||||||
13773890668: 71 833 4 7 7 9 528 7 78
|
|
||||||
28935437: 12 51 7 219 353 6 7 7
|
|
||||||
2400515: 480 5 4 55 60
|
|
||||||
761: 12 8 84 53 528
|
|
||||||
3640: 20 6 480 7 20 78
|
|
||||||
60299935213: 472 589 964 225 6 4 3
|
|
||||||
224408: 8 8 9 1 8 29 2 95 8 2 5 3
|
|
||||||
2046614307: 7 55 3 12 9 25 14 307
|
|
||||||
31922850999: 6 9 1 19 1 118 7 9 4 5 6 8
|
|
||||||
83457941113: 84 300 2 5 1 69 99 6 13
|
|
||||||
608409710: 58 4 6 1 4 52 7 41 55 2
|
|
||||||
819044459: 7 975 3 705 2 6
|
|
||||||
10019018: 93 43 97 430 18
|
|
||||||
2726736: 664 958 82 21 2 8
|
|
||||||
849157: 996 2 9 5 1 2 1 1 1 7 421
|
|
||||||
7278520: 1 2 981 6 3 2 1 9 4 8 5 61
|
|
||||||
118060806: 373 11 5 143 43 6
|
|
||||||
20902: 70 81 2 69 32 5 26 1
|
|
||||||
639450: 359 70 6 435 735
|
|
||||||
41696: 5 212 8
|
|
||||||
7392: 3 765 3 453 7 1 6
|
|
||||||
4249867874: 62 1 9 1 19 7 58 69
|
|
||||||
32408375: 32 40 832 5 5
|
|
||||||
1609379: 38 605 7 8 1
|
|
||||||
1045: 9 67 6 7 956
|
|
||||||
3060188: 8 606 1 818 9 2 6 5 8
|
|
||||||
288224602: 1 942 3 773 2 32 730
|
|
||||||
119: 4 3 93 8 6
|
|
||||||
26606: 8 49 7 671 3 9 6 4 5 633
|
|
||||||
70567960: 42 210 9 95 8
|
|
||||||
11162592: 89 9 9 493 12 98
|
|
||||||
1312192163295: 79 25 1 193 83 8 6 8 95
|
|
||||||
23027: 876 2 542 8 7
|
|
||||||
92299: 201 457 443
|
|
||||||
73140250: 102 581 713
|
|
||||||
134246144: 61 8 87 93 8 34
|
|
||||||
44: 9 3 8 22 3
|
|
||||||
66755594563: 55 62 9 1 1 4 42 3 6 4 4 3
|
|
||||||
1235240: 9 8 90 2 69
|
|
||||||
1167032: 9 40 2 7 38 4 7 9 7 9 73 2
|
|
||||||
2620881661: 8 7 362 3 9 6 6 656 5
|
|
||||||
187793: 8 179 692 98 1
|
|
||||||
47794: 3 69 3 43 44 65 8 76
|
|
||||||
284165701644: 99 706 353 701 644
|
|
||||||
335162944: 57 6 98 2 944
|
|
||||||
169260: 6 70 403
|
|
||||||
178035795: 38 34 9 7 9 40 6 3 755
|
|
||||||
66948420: 21 7 6 5 43 924
|
|
||||||
2479370: 247 93 50 3 16
|
|
||||||
6967886707: 696 7 88 6 705
|
|
||||||
31062240000: 49 1 6 5 53 8 4 5 74 33
|
|
||||||
8117959754763: 2 701 4 98 6 584 9 2 1 3
|
|
||||||
14179652599: 3 70 50 492 2 94 84 7
|
|
||||||
8834: 29 3 69 4 2
|
|
||||||
211195608: 67 686 1 48 8 39
|
|
||||||
9141370: 9 9 358 7 6 1 5 41 9 1 7 7
|
|
||||||
398636: 12 5 60 4 4 6 1 322
|
|
||||||
45629: 427 4 18 86 588 42 4 6
|
|
||||||
209140108: 701 1 16 49 7 38
|
|
||||||
54854749: 3 8 8 31 1 36 3 8 2 2 9 7
|
|
||||||
36782309: 3 59 8 80 2 307
|
|
||||||
5143959332411: 1 57 15 5 9 9 332 402 8
|
|
||||||
1602608: 3 91 8 5 349 9 2 3 688 5
|
|
||||||
37788: 6 8 7 687 3
|
|
||||||
283577: 1 9 13 263 995 2
|
|
||||||
115730: 9 3 2 124 26 2 56 8 9 2
|
|
||||||
20700: 48 2 2 7 49 3 6 7 991 53
|
|
||||||
276460: 25 6 6 415 3 6 70
|
|
||||||
3271850: 322 4 392 793 10
|
|
||||||
188703367670: 5 46 9 1 6 9 8 8 766 9
|
|
||||||
126394406: 141 169 6 649 7 880 6
|
|
||||||
43849535: 2 1 58 36 94 7 52 5
|
|
||||||
7113117119: 702 9 31 137 34 11 8
|
|
||||||
512831269: 9 29 572 229 883 15 4
|
|
||||||
886: 4 8 15 700 6
|
|
||||||
290874054503317: 5 9 986 8 10 900 663 5
|
|
||||||
1150293: 4 185 21 424 9 8 885
|
|
||||||
16808387: 45 747 23 5 8 764
|
|
||||||
338100965: 7 1 333 5 28 35 8 74 91
|
|
||||||
5743: 42 591 84 1 8 7
|
|
||||||
1017379449: 233 3 95 9 18 7 6 5 2 6 9
|
|
||||||
312579238: 665 2 442 1 89 2 2 991
|
|
||||||
436338339683: 55 5 392 436 7 1 1 46 4
|
|
||||||
47035605: 55 4 63 37 1 2 342 3
|
|
||||||
85619743907: 594 144 83 743 907
|
|
||||||
924237690: 1 8 1 37 6 9 34 11 7 688
|
|
||||||
43212856321: 65 367 1 2 856 276 45
|
|
||||||
5352: 506 7 39 7 9 10 1 8 303
|
|
||||||
244908: 27 62 917 23 3
|
|
||||||
136335660: 8 865 3 8 549 37 6 41
|
|
||||||
30147022: 597 8 8 789 910
|
|
||||||
267424: 1 932 3 2 6 1 5 68 1 137
|
|
||||||
651: 6 46 5
|
|
||||||
87604475: 8 1 725 4 236 79 2 8 9 2
|
|
||||||
11278205567: 765 7 7 490 8 724 36
|
|
||||||
30585804: 367 926 90 1 24
|
|
||||||
19147: 9 69 245 34
|
|
||||||
10826820: 520 7 522 33 68 15 5
|
|
||||||
12150: 81 2 75
|
|
||||||
4889: 80 6 1 5 3 9 9 1 9 380 18
|
|
||||||
120193530: 39 642 6 2 34 4 6 9 6
|
|
||||||
207977: 10 5 6 117 977
|
|
||||||
1324: 4 66 5 977
|
|
||||||
129600605: 2 5 4 331 720 7 5 3 252
|
|
||||||
33300996: 925 36 93 6 5
|
|
||||||
1551665414: 888 8 1 5 7 569 8 3 1 4
|
|
||||||
1281554136: 7 62 90 6 837 487
|
|
||||||
121034377174: 6 71 2 103 953 6 763 5
|
|
||||||
7706354167554: 7 539 475 3 878 43 9 8
|
|
||||||
17506596: 29 6 1 59 31 8 327 5 4 4
|
|
||||||
413531: 9 1 19 33 2 86 9 8 899
|
|
||||||
20895: 3 77 9 7 8 3 4 75 8 6 1
|
|
||||||
408404: 44 7 1 327 6 3 62 9 4 6 6
|
|
||||||
10722: 97 6 5 6 6 3 3 4 4 1 23 8
|
|
||||||
996: 1 7 5 965 1 6 7 5
|
|
||||||
507325: 6 83 5 88 25
|
|
||||||
29347686: 4 2 89 9 424 8 4 1 25 8 3
|
|
||||||
1356080: 3 129 876 8 4
|
|
||||||
518639: 3 9 4 5 3 7 168 7 7 9 2 5
|
|
||||||
68790276: 4 74 115 2 1 6 7 9 71 5 4
|
|
||||||
27608836421: 74 23 112 303 478 2
|
|
||||||
1866792852: 9 2 6 5 2 6 7 291 57 5 4
|
|
||||||
3227072784: 34 858 526 57 912
|
|
||||||
408841: 8 6 833 2 5 72 2 3 7 56 6
|
|
||||||
625: 82 77 6 5 453
|
|
||||||
710281278: 493 635 6 8 6 707 9 6 7
|
|
||||||
7947543334: 52 6 6 7 4 908 4 5 32 2
|
|
||||||
13287971: 8 1 3 4 4 797 2
|
|
||||||
920304107: 4 44 9 581 107
|
|
||||||
145: 2 6 4 95 2
|
|
||||||
1221276: 628 4 23 3 84
|
|
||||||
3152042325: 8 44 183 5 895
|
|
||||||
9004631: 878 46 64 31 294
|
|
||||||
32755464: 83 7 9 62 4 426 63
|
|
||||||
465434: 763 61 3
|
|
||||||
117023125: 95 9 11 871 949 3 9 4 1
|
|
||||||
5489531364874: 871 3 526 8 7 84 9 7 9 4
|
|
||||||
227647935510: 573 82 158 3 17 95
|
|
||||||
987686437: 289 89 64 6 37
|
|
||||||
489723554: 580 3 84 3 554
|
|
||||||
2980101: 348 83 916 94 9
|
|
||||||
932: 38 4 82 1 698
|
|
||||||
10720145: 9 9 2 1 3 913 6 4 31 9 38
|
|
||||||
1582199043: 331 239 95 2 44
|
|
||||||
4939116: 488 5 845 66 6
|
|
||||||
12960: 533 16 6 791 274 8
|
|
||||||
1131: 6 5 4 7 893
|
|
||||||
3956427580: 63 628 275 83
|
|
||||||
579603: 5 13 72 45 920
|
|
||||||
120: 2 44 31 1 1
|
|
||||||
707973546: 698 9 969 3 6 50 7 889
|
|
||||||
82171: 81 407 764
|
|
||||||
59078: 146 444 74 1 4
|
|
||||||
372416: 43 78 364 6 14
|
|
||||||
283157070382: 1 5 1 73 6 547 4 4 7 9 8 4
|
|
||||||
127665181: 753 6 892 46 513
|
|
||||||
3931604: 48 840 233 19 428
|
|
||||||
2922: 2 2 6 42 9 304 8 2
|
|
||||||
1628538200: 2 833 6 97 7 7 7 40 251
|
|
||||||
18933: 3 5 4 7 2 6 7 5 3 1 870
|
|
||||||
1983470022326: 85 1 1 3 8 5 72 2 5 6 97 6
|
|
||||||
1518804: 47 883 650 38 9 4
|
|
||||||
206771: 533 223 932 896 6 8 4
|
|
||||||
14944382: 55 3 94 1 15 936 9 323
|
|
||||||
420277: 87 5 9 133 987 7 3 1
|
|
||||||
3451113: 75 46 3 35 778
|
|
||||||
24826110: 973 81 9 5 7 15
|
|
||||||
2273099665: 5 7 2 5 690 397 735
|
|
||||||
2236642944: 64 6 9 46 835 96 79 68
|
|
||||||
184786375236: 229 83 38 804 36
|
|
||||||
3354043148: 7 93 846 609 8
|
|
||||||
45799: 59 10 64 3 7
|
|
||||||
29664054396: 886 310 6 45 72 6 2 4 9
|
|
||||||
22212: 60 256 7 8 56 28
|
|
||||||
320339168: 20 8 161 14 94 750 2 8
|
|
||||||
207560639: 8 597 883 85 31 2 70
|
|
||||||
5549006: 384 76 94 900 6
|
|
||||||
638281767: 97 5 96 6 654 3
|
|
||||||
14219040: 7 351 2 6 54 2 1 6 32 5 3
|
|
||||||
80115: 11 581 67 366 6 1 2 43
|
|
||||||
12344046: 78 4 2 8 21 2 117 74 2 2
|
|
||||||
25789271222525: 5 9 9 70 73 86 67 5 863
|
|
||||||
6248074: 37 584 3 80 75
|
|
||||||
69253: 9 3 1 33 8 9 3 24 6 3 616
|
|
||||||
5420650221: 45 6 1 20 6 491 4 108 1
|
|
||||||
82962: 5 2 69 7 7 729 3 3 3 6 1 3
|
|
||||||
28999: 604 13 47
|
|
||||||
1065075928: 80 2 3 99 4 664 1 6
|
|
||||||
127772: 77 823 401 75 2 78
|
|
||||||
130939215: 691 9 6 84 21 1 9 8
|
|
||||||
7660: 935 6 2 8 115
|
|
||||||
451212: 230 7 42 6 19
|
|
||||||
2247886690: 51 1 4 8 452 6 6 667 70
|
|
||||||
1811035556: 9 9 82 5 899 51 79 56
|
|
||||||
4109365120: 7 62 932 476 20 316
|
|
||||||
17089560: 4 5 8 43 3 43 6 512 10 9
|
|
||||||
22982: 8 55 52 93 9
|
|
||||||
186: 2 8 3 28 145
|
|
||||||
1377312127: 5 655 33 24 8 531 70 9
|
|
||||||
24621407: 548 52 2 432 863
|
|
||||||
57879912: 2 24 63 5 41 1 1 3 8 4
|
|
||||||
9319523: 224 416 8 3 23
|
|
||||||
210304: 4 162 9 9 74 14 4
|
|
||||||
87226: 96 3 3 2 80 7
|
|
||||||
2148130634: 20 77 642 3 22 34
|
|
||||||
112797844: 60 1 687 151 8 44
|
|
||||||
34875: 44 9 2 634 5
|
|
||||||
704382941: 3 9 462 6 9 3 2 8 1 533 1
|
|
||||||
514339: 5 1 4 33 7
|
|
||||||
91172: 3 34 7 7 779 805 3
|
|
||||||
10679126102: 7 7 410 3 2 99 8 671 62
|
|
||||||
917320: 32 3 4 710 1
|
|
||||||
55748: 151 5 7 51 5 1 9 9 4 2 6 7
|
|
||||||
982512: 13 3 221 459 9 376 9
|
|
||||||
434145: 3 3 8 97 8 99 5 6 8 7 61 8
|
|
||||||
1472458: 20 5 4 1 64 88 6 244 66
|
|
||||||
152: 78 4 8 2 60
|
|
||||||
1241: 22 2 83 80 6
|
|
||||||
2740059: 48 8 6 2 41 61 63
|
|
||||||
528: 494 32 2
|
|
||||||
4800: 57 138 26 79 16
|
|
||||||
1322689: 9 4 96 268 9
|
|
||||||
987420: 4 89 693 26 34 84 4 6 6
|
|
||||||
6243825: 8 615 1 3 825
|
|
||||||
2466861957: 881 7 4 42 7 183 9 54
|
|
||||||
4914: 3 2 819
|
|
||||||
11451: 94 96 3 20 51
|
|
||||||
23964156: 78 38 3 396 54 1 5 7 1
|
|
||||||
2163758589: 478 21 710 4 29 433
|
|
||||||
5237550860: 7 828 6 229 5 9 43 20
|
|
||||||
338665: 32 6 7 78 6 7 6 6 4 9 664
|
|
||||||
178: 3 7 9 80 8
|
|
||||||
2147171: 69 1 75 7 7 7 9 4 3 83 4 5
|
|
||||||
1605002: 27 9 71 5 93 8
|
|
||||||
256854564: 20 38 803 59 6 918
|
|
||||||
291006063: 8 6 4 6 2 505 20 9 6 5 4
|
|
||||||
3639475198: 42 13 9 129 862
|
|
||||||
77155930: 76 88 27 59 30
|
|
||||||
3946048: 95 472 44 33 4 2 9 7 38
|
|
||||||
2160667: 523 1 5 96 797
|
|
||||||
165008: 8 456 5 5 89 9
|
|
||||||
18151435: 8 37 9 53 395
|
|
||||||
5369239218: 8 59 8 9 238 1 215
|
|
||||||
5049390643: 7 651 7 4 52 591 8 9 43
|
|
||||||
56719056: 9 568 33 7 4 1 762 8 48
|
|
||||||
451791000: 33 46 19 8 58 30 9
|
|
||||||
2603596800: 7 779 8 629 668 640
|
|
||||||
1242803851704: 891 9 58 20 5 69 1 703
|
|
||||||
19728171: 543 5 4 9 17 1
|
|
||||||
726115: 7 1 2 3 336 5 20 5 2 6 9
|
|
||||||
197421: 4 7 7 4 80 345 2 594
|
|
||||||
342622733: 48 235 81 630 7 733
|
|
||||||
611736748: 972 247 91 97 28
|
|
||||||
5709688746: 6 8 20 6 8 8 7 9 84 59 93
|
|
||||||
26935: 8 7 13 267 9 3 1 1 51 8 9
|
|
||||||
1110319: 3 408 25 6 2 9 619
|
|
||||||
1729: 728 8 984 9
|
|
||||||
1516073592: 24 477 4 3 578 64 3
|
|
||||||
10192: 20 38 5 2
|
|
||||||
4199874129612: 658 8 64 668 724 9 7
|
|
||||||
4463235120291: 949 8 57 973 5 106 91
|
|
||||||
469476: 2 6 2 158 61 2 683 6 6 7
|
|
||||||
5635257: 9 6 2 29 3 6 52 2 3 5 1 6
|
|
||||||
139207: 1 870 2 8 7
|
|
||||||
2768307332: 477 5 4 7 9 2 49 1 94
|
|
||||||
115373519: 7 279 65 8 6 98 4 4 3 4 9
|
|
||||||
13997490486: 5 7 7 1 5 7 570 30 9 3 91
|
|
||||||
1680: 20 461 2 718
|
|
||||||
1270: 135 484 80 563 9
|
|
||||||
2821947: 4 6 5 6 56 2 9 6 895 7 3 2
|
|
||||||
825506: 1 77 28 3 382 6 98 3 4 8
|
|
||||||
393493259: 577 828 3 33 28 5 5 9
|
|
||||||
7301408: 145 67 35 41 6 4 128
|
|
||||||
63195971622: 1 51 6 633 5 3 9 9 4 3 8 3
|
|
||||||
2782104: 662 229 7 52 6
|
|
||||||
569: 8 17 537 3 4
|
|
||||||
146904291: 20 7 785 707 297 1 1
|
|
||||||
775581: 692 42 51 26 38
|
|
||||||
72170: 8 28 8 22 248 35
|
|
||||||
15580: 32 7 60 91 82
|
|
||||||
15137565: 8 2 1 3 37 267 667
|
|
||||||
4932150: 9 2 9 4 39 56 3 171
|
|
||||||
25927855: 81 4 8 765 20 2
|
|
||||||
79854: 7 1 3 7 9 94 3 3 20 8 9 6
|
|
||||||
22979158: 476 9 3 6 8 327 70 3 4
|
|
||||||
127781982: 47 80 5 268 28 30 3 43
|
|
||||||
2102: 5 4 83 9 295 2
|
|
||||||
105687: 32 33 13 4 70
|
|
||||||
36448653989: 36 44 865 321 3 776
|
|
||||||
170271265: 27 6 8 270 36 2 903
|
|
||||||
14111307: 2 1 5 2 2 21 5 265 64 7 9
|
|
||||||
34356195344: 4 966 68 794 9 656
|
|
||||||
213840: 55 8 9 6 9
|
|
||||||
919113216: 74 6 6 4 6 7 1 9 3 9 888 7
|
|
||||||
4412885624: 7 500 5 17 9 7 9 85 27 2
|
|
||||||
109: 1 4 98
|
|
||||||
9371772: 2 2 4 4 2 485 26 6 1 8 3
|
|
||||||
816: 3 41 43 9 6 8
|
|
||||||
372878004: 997 85 440 4
|
|
||||||
1080585: 731 342 5 1 6 9 2 96 1 2
|
|
||||||
200215: 77 2 4 90 63
|
|
||||||
618205474: 3 9 21 3 245 70 472
|
|
||||||
814900: 76 13 49 87 725
|
|
||||||
19021857936: 13 2 5 2 8 7 2 9 4 977 9 7
|
|
||||||
7647520449: 4 79 5 9 3 5 3 83 7 8 3 97
|
|
||||||
27673593644: 7 611 2 6 7 59 308 4
|
|
||||||
5303585976395: 86 3 46 67 6 988 388 9
|
|
||||||
4761: 2 4 8 7 2
|
|
||||||
47095296: 4 969 5 5 2 3 2 3 8 3 54 6
|
|
||||||
540397305: 4 55 983 204 3 734 81
|
|
||||||
29687553: 92 4 537 579 6 81
|
|
||||||
1323: 41 295 988
|
|
||||||
7119955: 2 637 9 3 57
|
|
||||||
25443072: 96 704 18 576 1 54
|
|
||||||
5959: 9 725 10 8 7
|
|
||||||
4114: 3 5 257 131 35 93
|
|
||||||
82044355016: 92 332 3 93 95 4 7 76 4
|
|
||||||
294366037: 4 56 11 247 63 33 5 89
|
|
||||||
214663955220: 2 5 29 7 7 901 429 30 6
|
|
||||||
3262: 50 9 16 7
|
|
||||||
11457938: 416 5 486 56 2
|
|
||||||
906440: 19 1 75 60 34
|
|
||||||
2191342561199: 330 8 5 444 4 153 975
|
|
||||||
437950713: 145 7 6 9 8 50 713
|
|
||||||
246758: 92 9 297 781 61
|
|
||||||
82810: 12 975 58 72 7
|
|
||||||
7891: 73 11 578
|
|
||||||
1255272: 125 42 9 81 91
|
|
||||||
27973: 3 23 4 79 11 282
|
|
||||||
68667: 678 3 6 77 7
|
|
||||||
136624821: 673 29 831 7 1
|
|
||||||
41550483: 74 9 55 6 58 687 853
|
|
||||||
309186514: 2 3 6 98 6 545 447 7 91
|
|
||||||
8249343115: 94 70 12 87 3 109 6
|
|
||||||
399336: 62 8 11 22 226 8 7
|
|
||||||
795786: 4 89 439 7 89
|
|
||||||
298384: 83 7 1 7 9 42 8 7 6 2 6 4
|
|
||||||
11562407: 6 9 8 4 16 5 1 5 7 6 240 5
|
|
||||||
186661952: 9 7 274 698 61
|
|
||||||
34885431: 387 508 56 40 3 917
|
|
||||||
2067520: 89 16 841 7 910
|
|
||||||
128753: 45 4 3 93 7
|
|
||||||
511005: 8 8 43 857 7 5
|
|
||||||
28633297: 78 29 892 3 97
|
|
||||||
63180: 46 596 44 91 3 81
|
|
||||||
990793851: 7 5 9 2 4 8 3 39 3 6 3 51
|
|
||||||
16421139602: 9 67 3 6 4 27 6 1 69 6 1 2
|
|
||||||
139: 6 8 91
|
|
||||||
1649833: 3 3 738 902 833
|
|
||||||
2671786336: 26 717 7 7 75 858 6
|
|
||||||
10141397: 55 790 4 3 44 9 951
|
|
||||||
2464139376: 734 563 5 9 31 9 586 4
|
|
||||||
424715: 9 4 501 9 869
|
|
||||||
81979110546: 910 879 90 54 5
|
|
||||||
2986635261: 1 70 96 4 61 88 599 3
|
|
||||||
2152893601: 6 9 1 6 2 97 85 492 8 5 3
|
|
||||||
61426224: 4 3 85 8 8 978
|
|
||||||
40496968: 3 1 5 5 9 847 49 9 7 84 2
|
|
||||||
30897645282: 8 6 55 921 933 33 7
|
|
||||||
22188546846: 9 8 2 40 9 3 136 7 4 47
|
|
||||||
18083286: 2 5 4 78 1 522 44 24 1 2
|
|
||||||
33589182: 5 36 96 16 43 533 9 46
|
|
||||||
538: 4 91 7 80 4 77 6
|
|
||||||
2803584: 9 97 9 7 6 3 73 8 2 9 5 56
|
|
||||||
8723: 9 78 1 2 3
|
|
||||||
52823506: 528 23 494 9 2
|
|
||||||
53738020: 99 68 53 110 72 820
|
|
||||||
205872: 2 71 5 5 2 2 9 8 7 1 855 8
|
|
||||||
676868645553: 6 685 83 686 1 45 550
|
|
||||||
193662: 5 6 4 8 1 18 8 5 929 5 1 2
|
|
||||||
80168990: 2 8 1 1 20 8 7 4 87 8 55 1
|
|
||||||
39364: 7 656 1 49 8 260 8 84
|
|
||||||
5957812: 52 5 9 4 7 791
|
|
||||||
10356: 79 4 63 6 12
|
|
||||||
34261: 4 54 9 5 6 4 5 491
|
|
||||||
749180: 23 9 137 676 95 797
|
|
||||||
4663718: 6 78 1 474 3 1 743 7 38
|
|
||||||
1925011: 40 59 4 814 715
|
|
||||||
52506566150: 6 2 7 5 6 3 2 9 6 661 50
|
|
||||||
8945777399: 6 7 90 5 3 15 3 15 2 39 9
|
|
||||||
3028272604: 484 8 638 552 604
|
|
||||||
188437635: 5 436 5 4 9 72 8 12 2 1 1
|
|
||||||
181156501: 6 48 31 50 567 1
|
|
||||||
325638624: 8 3 800 44 4 841 60
|
|
||||||
8032850: 79 52 7 73 767 19 64
|
|
||||||
433839131280: 2 1 3 3 8 7 6 5 454 10 2 4
|
|
||||||
86385975: 69 36 1 1 535 75 65
|
|
||||||
13686: 46 2 280 1 245
|
|
||||||
1712014581552: 341 2 621 4 44 11 57 4
|
|
||||||
1489310550: 78 449 9 9 525
|
|
||||||
255151481: 54 51 1 27 5 18 69 78 8
|
|
||||||
63232569: 23 47 98 94 16 4 569
|
|
||||||
15505: 8 35 30 1 5
|
|
||||||
489767: 5 960 102 89 78
|
|
||||||
325626915: 395 6 8 914 68 2 9 5 1
|
|
||||||
14129837307: 28 90 7 239 89 652 9
|
|
||||||
764: 721 5 33 6
|
|
||||||
4223: 7 463 56 919 7
|
|
||||||
166163510506: 16 531 6 847 510 506
|
|
||||||
587419833297: 3 37 6 882 9 69 33 2 97
|
|
||||||
399277947: 31 8 927 7 664 2 281
|
|
||||||
170242241098: 49 39 425 38 8 13 907
|
|
||||||
5668108: 9 227 545 6 58
|
|
||||||
203298244380: 6 69 493 315 964
|
|
||||||
33496949455: 809 49 35 1 845 6 249
|
|
||||||
501967675: 7 9 1 784 5 3 6 6 7 62 5 5
|
|
||||||
1876910: 5 4 6 2 8 4 389 5 6 708 2
|
|
||||||
2965650: 3 707 8 50
|
|
||||||
118205: 95 51 42 2 99 4 2 261
|
|
||||||
100089048: 8 4 2 70 3 4 4 7 825 2 3 8
|
|
||||||
46834203: 9 4 41 9 6 135 4
|
|
||||||
88282419: 44 2 282 4 17
|
|
||||||
1181936466: 1 6 3 9 72 22 94 7 1 6 7 5
|
|
||||||
16346: 8 7 4 86 6
|
|
||||||
79124454: 6 4 6 3 2 4 20 310 3 9 2 3
|
|
||||||
8135081494: 8 1 1 338 7 6 938 3 8 6 8
|
|
||||||
333717154: 3 918 472 3 530 3 65 4
|
|
||||||
58432: 3 900 2 8 64
|
|
||||||
26363: 9 7 82 269 1
|
|
||||||
2099820378: 443 5 948 375 3
|
|
||||||
12057: 632 2 19 3 8
|
|
||||||
147361111: 917 7 7 49 78 3 4 6 3 34
|
|
||||||
1045885343: 7 249 6 853 46
|
|
||||||
170369280: 87 4 7 6 24 2 46 120
|
|
||||||
669944977: 331 46 44 97 7
|
|
||||||
257509: 263 583 5 61 60 49
|
|
||||||
1757606033: 258 4 7 17 2 3 67 4 562
|
|
||||||
4072900: 6 65 918 216 4 845
|
|
||||||
984: 2 4 77 866 17
|
|
||||||
1530342088: 128 6 17 140 28 389 5
|
|
||||||
171554880: 128 480 8 346 56 588
|
|
||||||
1018072: 2 4 8 9 1 87 598 9 88 1
|
|
||||||
2349979998225: 78 332 66 57 9 3 223
|
|
||||||
3024234657: 64 2 95 6 17 41 1 48 55
|
|
||||||
1515192: 621 1 29 7 4 3
|
|
||||||
305325282: 272 33 31 91 61 82
|
|
||||||
54685: 7 18 9 3 1 2 4 9 7 82 38
|
|
||||||
71892: 3 9 69 79 98 9 5 7 93 4 9
|
|
||||||
221909351484: 78 8 219 359 2 547 6
|
|
||||||
799880400: 6 9 4 9 747 250 4 3 396
|
|
||||||
26946: 2 2 3 8 1 9 4 221 8 3 4 6
|
|
||||||
280535: 7 811 3 341 565 11
|
|
||||||
7694: 11 699 3
|
|
||||||
77108114084: 2 50 4 320 3 6 4 8 5 21 4
|
|
||||||
2144050592168: 1 4 97 6 6 9 3 3 8 402 1 8
|
|
||||||
514177: 4 54 6 3 47 2 5 4 4 333 5
|
|
||||||
5795806: 49 117 118
|
|
||||||
255481250: 4 121 82 997 25
|
|
||||||
53713731064: 7 89 7 8 9 4 9 6 3 1 674 1
|
|
||||||
3827: 2 64 6 38 7 789
|
|
||||||
12069: 302 37 9 9 875
|
|
||||||
26340: 5 40 49 633 86 5
|
|
||||||
39004: 9 1 66 3 49 40 7 77 98
|
|
||||||
199466019: 88 909 2 1 3 5 4 5 5 2 4 4
|
|
||||||
94346225618: 548 1 5 879 559 5 7 7 1
|
|
||||||
411053: 97 5 6 31 3 3 9 5
|
|
||||||
15666: 54 4 72 2 19 3 84 6
|
|
||||||
7685786934: 768 5 713 73 919 14
|
|
||||||
2639: 565 1 804 487 783
|
|
||||||
116657452: 5 5 29 9 8 4 9 7 2 3 5 2
|
|
||||||
391689: 1 3 4 1 240 96 9
|
|
||||||
20629030: 3 3 685 4 96 49 30
|
|
||||||
92190575: 9 85 162 357 798 57 5
|
|
||||||
200187465: 5 3 7 2 7 1 7 470 7 298 6
|
|
||||||
841: 7 2 5 5 491
|
|
||||||
2124: 3 593 2 343
|
|
||||||
36610063992: 2 43 93 9 4 918 554
|
|
||||||
114822786: 181 97 654 9
|
|
||||||
10260285: 5 1 371 137 200 2 85
|
|
||||||
16025920: 7 6 188 21 1 9 638
|
|
||||||
17613507: 6 15 3 45 9 807 3 8 6 3
|
|
||||||
239580: 1 83 310 2 484
|
|
||||||
2027025: 779 40 55 3 15
|
|
||||||
7115144510: 89 890 45 945 283 95
|
|
||||||
3388245182269: 9 89 846 679 7 489 54
|
|
||||||
1595992599927: 2 85 10 6 3 933 92 6 1
|
|
||||||
4531547: 93 5 6 1 1 6 118 8 7 20
|
|
||||||
789698706: 635 9 658 6 35 6
|
|
||||||
1433136093: 4 9 64 27 5 818 750 93
|
|
||||||
424116828954: 580 43 483 918 741
|
|
||||||
139600188: 516 991 3 91
|
|
||||||
120808840: 9 9 9 7 851 564 6 7 1 7 5
|
|
||||||
10581: 48 19 1 673 786 4
|
|
||||||
82117538: 5 1 79 33 5 9 94 63
|
|
||||||
27964789: 21 257 656 987 4 86 5
|
|
||||||
956: 9 35 21
|
|
||||||
3163734: 554 79 833 6 1
|
|
||||||
583: 3 1 9 571
|
|
||||||
1161556284: 3 427 5 9 8 1 4 6 9 73 1 8
|
|
||||||
605316855: 867 9 37 65 29
|
|
||||||
7787780235: 7 9 6 382 7 41 5 303 3
|
|
||||||
1267497: 2 13 7 3 400 6 4 2 3 2 4 5
|
|
||||||
21273569: 96 695 55 78 5 4 337
|
|
||||||
5218526406: 700 35 710 88 30 8
|
|
||||||
6422539915: 8 896 896 8 109 2 18
|
|
||||||
7471037503: 965 9 959 897 2 746
|
|
||||||
1760697625: 5 2 7 60 697 623
|
|
||||||
104951442: 954 22 4 8 3 7 2 1 6 59
|
|
||||||
796965533: 29 3 4 34 4 7 2 84 5 612
|
|
||||||
2637180: 90 25 49 6 78
|
|
||||||
65441892692: 6 544 18 92 692
|
|
||||||
2055416: 63 303 62 48 3 96 2 9
|
|
||||||
3726049: 8 88 3 84 154 481
|
|
||||||
192424: 9 71 8 248 3 8 11 21 8
|
|
||||||
114575369: 387 925 73 32 9
|
|
||||||
730: 4 4 2 66 8 58
|
|
||||||
894217550: 565 989 8 801 6 8 6 5 5
|
|
||||||
126551425: 2 371 131 652 97 385
|
|
||||||
4561: 4 8 5 116 8 9 3 31 5 1 9 2
|
|
||||||
85412348: 773 3 9 3 7 7 1 79 6 8 7 4
|
|
||||||
8653448: 6 989 27 31 1 6 9 2
|
|
||||||
38808424190: 10 485 93 8 4 302 4 8
|
|
||||||
8051: 3 80 97
|
|
||||||
5219: 974 114 4 8 15 6 830 8
|
|
||||||
15324: 90 2 82 4 560
|
|
||||||
6746536845: 70 878 8 8 711 45
|
|
||||||
1191528: 1 6 289 260 72
|
|
||||||
177897089474: 8 7 68 8 555 43 75 51
|
|
||||||
2678692: 267 869 2
|
|
||||||
651553: 2 2 6 2 18 1 9 352 69 5 8
|
|
||||||
143: 92 7 30 8 6
|
|
||||||
233481: 3 602 438 3 900 4 44
|
|
||||||
230845835: 5 225 796 1 45 4 829 5
|
|
||||||
616135338477: 13 868 46 1 7 6 91 479
|
|
||||||
19341080: 48 35 4 50 1 3 567
|
|
||||||
8588906: 478 3 6 4 93 2 8 147 7
|
|
||||||
885519043205: 790 76 118 4 9 40 71 3
|
|
||||||
3872: 5 3 226 482
|
|
||||||
3514395790: 5 2 3 9 3 3 5 8 95 741 49
|
|
||||||
53662: 55 97 1 5 97 8 42 149
|
|
||||||
5088: 26 4 48 89 7
|
|
||||||
359229: 1 437 12 8 29
|
|
||||||
36437462: 7 3 49 13 936 1 4 4
|
|
||||||
86296: 3 1 6 5 5 2 2 2 553 7 21
|
|
||||||
131253470: 201 653 47 2 5
|
|
||||||
5445324: 2 10 5 508 9 9 5 958 24
|
|
||||||
60870634648: 5 806 8 72 8 4 9 472
|
|
||||||
16988: 2 75 261 41 137
|
|
||||||
53595: 45 936 8 6 12 2 7 9
|
|
||||||
922311575: 184 462 315 5
|
|
||||||
6210: 161 3 43 3 2
|
|
||||||
23761847403: 8 1 238 9 33 7 23 6 6 7 9
|
|
||||||
69625: 9 10 6 7 47 2 458 7 2
|
|
||||||
27763: 3 23 9 41 1 747 8 4 3 8 8
|
|
||||||
3052647: 5 65 438 4 647
|
|
||||||
3381704: 59 5 1 164 9 4 206 1 3 2
|
|
||||||
4970: 5 21 47 6 31
|
|
||||||
118: 98 2 4 8 6
|
|
||||||
8316014: 1 971 19 84 13
|
|
||||||
3465: 138 5 10 32 2 1 2 528 7
|
|
||||||
3530332260: 8 7 2 767 910 9
|
|
||||||
12063293616: 6 4 5 62 1 2 86 1 7 1 5 16
|
|
||||||
5536: 7 37 87 16
|
|
||||||
1179238531713: 815 95 78 651 222
|
|
||||||
27708: 2 7 175 5 528
|
|
||||||
3879901: 3 746 69 51 75 1
|
|
||||||
5067983: 5 3 3 4 154 1 12 5 3 608
|
|
||||||
42455989: 4 9 9 30 5 7 1 794 7 8
|
|
||||||
359560160: 5 425 56 10 41 16
|
|
||||||
5120: 493 7 13 776 880
|
|
||||||
87496046313: 910 9 1 1 95 5 5 4 6 315
|
|
||||||
60686: 319 5 2 38
|
|
||||||
106937025061: 9 276 5 827 3 250 61 1
|
|
||||||
29347: 111 257 503 2 315
|
|
||||||
614534: 6 8 6 3 947 4 878
|
|
||||||
24659: 465 7 51 585 2
|
|
||||||
2296436: 635 55 832 29 4
|
|
||||||
6149400: 80 25 85 641 50 148
|
|
||||||
1924040510520: 80 6 72 5 6 5 713 93
|
|
||||||
220087571: 55 40 8 757 1
|
|
||||||
610462400: 6 6 1 7 40 934 76 5
|
|
||||||
3531963: 3 957 5 41 6 3
|
|
||||||
698721408: 113 4 6 6 9 4 4 8 8 9 4 4
|
|
||||||
5148269: 45 880 6 13 191
|
|
||||||
628: 141 1 78 192 199 18
|
|
||||||
103117571: 91 12 994 95 11
|
|
||||||
1484996971: 716 768 99 697 1
|
|
||||||
20880: 4 3 58 5 6
|
|
||||||
7404612: 79 7 1 86 12
|
|
||||||
30842169828: 6 168 3 1 5 1 697 4 1 87
|
|
||||||
59759: 79 5 6 47 19 3 7 7 1 8 7
|
|
||||||
38429118000: 91 49 91 6 4 435 809
|
|
||||||
318576716: 3 44 1 9 815 98 47 7 94
|
|
||||||
5897: 7 8 397 29 4 2 4 8 3 8 5 4
|
|
||||||
4722: 46 4 82 8 614
|
|
||||||
193939725: 6 390 296 280 528
|
|
||||||
7908668418: 5 9 3 75 98 4 352 781 2
|
|
||||||
1080: 6 9 96 5 525
|
|
||||||
78879: 33 42 3 45 640 2 157
|
|
||||||
16555109276: 8 3 2 1 6 24 9 2 9 1 346 6
|
|
||||||
46600957875: 2 3 7 38 5 61 3 784 7 28
|
|
||||||
619697449: 19 1 2 6 86 5 77 1 8 8 9
|
|
||||||
17149600: 8 67 267 992 50
|
|
||||||
90: 2 2 1 2 9
|
|
||||||
567900: 2 59 815 6 2 6 4 9 8 7 9
|
|
||||||
179229819: 2 56 7 298 22
|
|
||||||
5464512: 1 411 62 80 6 6 7 9 2 8 9
|
|
||||||
318552570: 7 325 37 14 7 67
|
|
||||||
7281: 1 904 8 35 6
|
|
||||||
36284: 36 263 21
|
|
||||||
146: 86 1 60
|
|
||||||
960991455: 9 60 17 3 4 787 442 4 9
|
|
||||||
1636416607: 85 559 205 6 4 7 7
|
|
||||||
7640592: 1 6 3 493 738 6 7 1 7 57
|
|
||||||
61572395640: 6 1 85 2 1 5 5 43 9 345 8
|
|
||||||
316803329: 70 7 6 45 1 1 974 4 6 5 3
|
|
||||||
119040: 5 46 43 4 3 1 7 273 2 6 4
|
|
||||||
102523960284: 854 366 3 1 3 6 8 8 6 5 4
|
|
||||||
1796198: 914 5 3 7 791 92 89
|
|
||||||
91670: 66 824 103
|
|
||||||
4758: 7 59 9 4 10 498
|
|
||||||
2932560: 12 2 1 8 7 6 64 8 1 99 60
|
|
||||||
2466642: 24 66 642
|
|
||||||
2516: 4 49 3 3 9 37
|
|
||||||
39268: 8 49 60 8
|
|
||||||
388603: 476 815 639 16 8
|
|
||||||
286225867: 21 6 106 25 867
|
|
||||||
111798479: 4 31 144 6 3 831 8 4 95
|
|
||||||
4432: 1 4 17 4 85 2 4 8
|
|
||||||
76038195: 99 3 77 68 7 42 5 527 3
|
|
||||||
75741848: 5 40 5 8 2 9 9 1 3 8 7 91
|
|
||||||
3223727766: 5 7 1 3 9 7 85 4 1 9 301 4
|
|
||||||
259448: 5 147 5 85 2 198
|
|
||||||
11318777470897: 4 8 262 41 9 412 9 95
|
|
||||||
50547: 4 1 95 21 8 7 97 975 5
|
|
||||||
125447831: 32 60 7 651 1 32
|
|
||||||
3164824079999: 580 8 12 8 4 860 33 4 6
|
|
||||||
621945: 497 283 33 9 85 1
|
|
||||||
126774605416: 74 573 297 3 17 6
|
|
||||||
12802698: 73 40 81 474 48 9
|
|
||||||
6289: 5 1 57 37 49
|
|
||||||
22886763: 68 840 67 29 9 5 8
|
|
||||||
45506381: 408 531 49 3 70 2 9
|
|
||||||
1086077699545: 15 29 686 9 71 545
|
|
||||||
96330: 9 7 8 569 735 1
|
|
||||||
26524275: 873 51 28 652 17 9 7 8
|
|
||||||
17287261563680: 882 49 4 615 63 677
|
|
||||||
488039: 4 8 6 3 59 69 7 4 8 8 9 95
|
|
||||||
2937672: 82 1 2 4 6 243 394 18
|
|
||||||
2991816576: 6 751 2 6 31 6 56 984
|
|
||||||
442230660: 1 60 226 6 19 276
|
|
||||||
93051972: 368 1 280 71 9 73
|
|
||||||
1160: 7 5 131 740 211
|
|
||||||
4941982155: 81 61 9 82 14 3 12
|
|
||||||
36760: 5 4 5 64 655 9 4 280 4 5
|
|
||||||
5418: 3 3 25 68 7 3 1 2 6
|
|
||||||
86247005055: 35 1 8 636 8 6 737 29 5
|
|
||||||
190642: 5 346 9 8 3 118 3 52 8 2
|
|
||||||
434695950: 2 846 36 7 4 4 7 51 3 93
|
|
||||||
1911065788: 195 980 6 578 8
|
|
||||||
25555915: 57 3 8 73 7 11 524 38 3
|
|
||||||
95100: 6 5 8 39 2 4 5 987 4 7 3 6
|
|
||||||
28837000: 1 8 97 1 8 584 9 9 4 250
|
|
||||||
505569315: 543 931 35 519 1 796
|
|
||||||
41223: 6 687 2
|
|
||||||
901: 21 6 4 870
|
|
||||||
8637229: 991 585 548 75 1
|
|
||||||
163576: 162 96 287 60 5 75 1
|
|
||||||
962371163023: 213 860 25 83 1 5 3 15
|
|
||||||
109350192: 7 57 1 7 9 1 405 258 4 6
|
|
||||||
16613281652: 7 383 8 1 85 624 9 5 2
|
|
||||||
9596305077: 6 70 5 8 7 401 2 2 6 6 5
|
|
||||||
17875933357: 644 63 9 881 5 7 5 8
|
|
||||||
89783: 9 6 6 2 15 96 503
|
|
||||||
27300689: 3 5 64 1 38 5 2 7 838 9
|
|
||||||
764541238248: 9 4 6 9 6 7 1 654 78 1 4 2
|
|
||||||
658436: 86 66 2 270 395 4 8 3 6
|
|
||||||
8419432: 84 1 94 18 4 8
|
|
||||||
859023: 1 9 7 7 3 50 858 8 5 8 7 9
|
|
||||||
14951976: 266 30 48 344 39
|
|
||||||
59478: 38 2 212 80
|
|
||||||
83264: 76 8 3 957 5
|
|
||||||
239182: 8 191 31 1 2 1 6
|
|
||||||
1108645374204: 8 6 8 4 2 388 3 2 93 20 4
|
|
||||||
12300944: 61 5 4 1 83 5 2 5 8 8 2 5
|
|
||||||
7204006: 2 90 4 249 145 3 65
|
|
||||||
258603731420: 71 834 6 2 3 2 1 3 1 420
|
|
||||||
3464130: 86 4 2 41 30
|
|
||||||
2125224: 5 812 18 2 9 96 72
|
|
||||||
15015078406: 175 858 78 358 49
|
|
||||||
17380390: 49 358 9 7 9 41 4 8 8
|
|
||||||
9550084: 18 829 8 8 4
|
|
||||||
20665420: 9 9 7 3 92 1 2 1 580 6 3 8
|
|
||||||
7411523885: 223 3 68 4 152 38 88
|
|
||||||
1106464: 389 45 53 32 71
|
|
||||||
1180722080: 478 1 245 6 5 2 20 503
|
|
||||||
3184109157: 87 602 2 6 770 51 50 7
|
|
||||||
113071859: 7 540 22 3 2 29 7 9 2 6 5
|
|
||||||
868: 3 7 8 4 35 4 3 7 7 5 283 6
|
|
||||||
2153328173529: 951 5 9 452 173 529
|
|
||||||
6349117323: 4 62 3 81 5 6 455 174 3
|
|
||||||
2309765691: 35 37 18 40 709 2 8 3
|
|
||||||
7943: 87 81 26 869 1
|
|
||||||
9289401: 7 6 581 2 342
|
|
||||||
1562470: 3 4 252 17 182
|
|
||||||
3575975392: 3 3 903 216 8 44
|
|
||||||
2171436: 21 3 1 20 4 2 5 2 9 8 1 24
|
|
||||||
46506582: 95 679 6 5 6 491 88
|
|
||||||
136519099056: 8 975 9 571 92 81 3
|
|
||||||
2390175: 94 611 15 48 45 5
|
|
||||||
8295222: 768 5 8 45 6 73 8 741
|
|
||||||
20445495: 61 85 20 785 7
|
|
||||||
27369402341: 999 9 6 6 1 8 7 4 2 1 4 95
|
|
||||||
15647742: 99 92 174 30 9
|
|
||||||
19937073: 36 6 1 2 6 7 20 3 77
|
|
||||||
217602: 6 2 1 4 5 730 2 2 552 4 2
|
|
||||||
1077224: 78 2 408 33 7 97
|
|
|
@ -1,50 +0,0 @@
|
||||||
.AU..Z.....8.......................t..C.6.........
|
|
||||||
..................................................
|
|
||||||
.....K.U....................v.....................
|
|
||||||
...Z..A.............................v8.....t......
|
|
||||||
p..................a8...........b...t.............
|
|
||||||
..pU.....A..4.....................................
|
|
||||||
..........................E.......................
|
|
||||||
...........K..V..............v8.....Cb............
|
|
||||||
....V................b...p........................
|
|
||||||
....7.............................................
|
|
||||||
....4.....A..........V......K..E.....6............
|
|
||||||
.4.........................Vb...........0..C......
|
|
||||||
..................................k........N......
|
|
||||||
K....7...........9...........6.....kE.............
|
|
||||||
......7......1...................k.......C........
|
|
||||||
...p....................9....0.....N6.............
|
|
||||||
..........Z........e..1...........................
|
|
||||||
.............................E................N...
|
|
||||||
...4...............................v0..........z..
|
|
||||||
........U.....Z......1................z..a........
|
|
||||||
.....5.......7......................N.............
|
|
||||||
....................n.............................
|
|
||||||
.......................0.9...c..........z.d.T.....
|
|
||||||
...................n.W......a...t......D....d.....
|
|
||||||
..........I.....e......................o9.........
|
|
||||||
....5..2................e...........D.............
|
|
||||||
...........................n......D...............
|
|
||||||
......25I...1..................c......W.......o...
|
|
||||||
................n..............D..................
|
|
||||||
...........I........i..e..........................
|
|
||||||
......5......2.....P..............a...............
|
|
||||||
...........................z..................T...
|
|
||||||
..........j.....................Wd...........O..o.
|
|
||||||
................................................c.
|
|
||||||
.................I................B...............
|
|
||||||
...........u.............................T.d......
|
|
||||||
.............................................J....
|
|
||||||
.....3.i....u......................o..............
|
|
||||||
3...i.............................................
|
|
||||||
..................................................
|
|
||||||
...........j...............W....O............w....
|
|
||||||
...P........................J.....................
|
|
||||||
.....u............................................
|
|
||||||
.............................w....................
|
|
||||||
......u.................2...w...J.................
|
|
||||||
.....j.....B3......................O..............
|
|
||||||
P....B..............................c.............
|
|
||||||
................B.............w...................
|
|
||||||
.....i.............3..............................
|
|
||||||
..P.j....................J..........O.............
|
|
File diff suppressed because one or more lines are too long
|
@ -1,54 +0,0 @@
|
||||||
212521982345455432198898732343201001454321076767899872
|
|
||||||
101430671156766718089087001432102122367410789898721701
|
|
||||||
234549560049859809670106126549893432198523650127630652
|
|
||||||
345678432132343218543215437456784543007694540134544543
|
|
||||||
434989010101034567894326458941089656912784343296531014
|
|
||||||
123968523218954326287478947032178767843895256787432543
|
|
||||||
037879654305869210156565432142189626756706101208956632
|
|
||||||
010968760456778981432101943443076212389617890312347701
|
|
||||||
323459821678765476583201875654561003476526345423698801
|
|
||||||
011234734569012345694112766743432876565430256784510932
|
|
||||||
010345654554212014785073450898101986676321100898929841
|
|
||||||
143456703623103423456787321287632987685672901289838750
|
|
||||||
212769812514398512987896544379443456894589874356745669
|
|
||||||
301898453405487600121095434568543670123601065105210178
|
|
||||||
498782345654676321436784323877612589010892110234312321
|
|
||||||
567101908723521030545654012981003438756763323987603430
|
|
||||||
323877819810437841690343021542312321065654332109544543
|
|
||||||
014966521923456956781252120455401487654505445678037652
|
|
||||||
565455430810398105898763214345566590123218764789128781
|
|
||||||
678321876760567234237454905216697687689439653234569390
|
|
||||||
549050945651456340145667876107788014578321342106778434
|
|
||||||
432167834512301254206758989038979123065430211067884521
|
|
||||||
212058723003456763219843210123460132104321203458990690
|
|
||||||
103449012124567895430764505674321043895650432143021788
|
|
||||||
214530101013098986721256034985452344786766501032134659
|
|
||||||
345621232322121234890340125676965435689897865401235678
|
|
||||||
238789985421030345234543234767876105476101974321945234
|
|
||||||
129376576534781676167652149866765256785232389450876165
|
|
||||||
023403456215696787018967019875454343494341071265210074
|
|
||||||
016512567304345698101278112562343852014556780374391189
|
|
||||||
187876458412234598790349603401438961025698895489580543
|
|
||||||
098962389561103347685456784876547873234767216785671672
|
|
||||||
123451049870101256576545692910687210189854306894502981
|
|
||||||
212945432943232345677834501431296332182344345663213870
|
|
||||||
301876501854569431988925232321345345091103216756344561
|
|
||||||
676510345763078520123810123410543456780234109865432150
|
|
||||||
783401256762107019654320294567632109876542106776843001
|
|
||||||
892313879856234198734521287678932323438943769089987612
|
|
||||||
341054965447895287645632789456541010567659858123656543
|
|
||||||
250123832332196014532745610367692101298365647654567698
|
|
||||||
167814001541087123691821001298789854303234737843238787
|
|
||||||
078905123456789234780934789656730763214159826943129898
|
|
||||||
980876432965410165690695678749821278934067015652010789
|
|
||||||
801986501874321074321783265637832123653458234761001656
|
|
||||||
212567988965010787210654104521945034562109101891012347
|
|
||||||
123498677654321298323545003010876453078045610123456798
|
|
||||||
034014576103432186789276512123289342199236769032347810
|
|
||||||
145623985412545085652189467898100256787100898741016921
|
|
||||||
898767234307696198543011056967221105107231239653455430
|
|
||||||
745678101268987585654322343254339012218774381012768741
|
|
||||||
234989089456789676789113698107448763329783498019889650
|
|
||||||
101345674301410566541004567898758954458692567325676341
|
|
||||||
013216765210323455632123476127667763067501101234765432
|
|
||||||
322109876323454556789012981034554892155432101289876501
|
|
|
@ -1,32 +1,2 @@
|
||||||
use crate::utils;
|
pub mod part_1;
|
||||||
|
pub mod part_2;
|
||||||
fn abs_diff(l : &u32, r : &u32) -> u32 {
|
|
||||||
if l >= r { l - r } else { r - l }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn answer(text : String) -> ( u32, u32 ) {
|
|
||||||
let ( mut left, mut right ) = from_string(text);
|
|
||||||
|
|
||||||
left.sort_unstable();
|
|
||||||
right.sort_unstable();
|
|
||||||
|
|
||||||
( left.iter()
|
|
||||||
.zip(right.iter())
|
|
||||||
.map(|(x, y)| abs_diff(&x, &y))
|
|
||||||
.sum()
|
|
||||||
// Part 2 can probably be optimized further but it might not matter
|
|
||||||
, left.iter()
|
|
||||||
.map(|x| right.iter().filter(|y| x == *y).count() as u32 * x)
|
|
||||||
.sum()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_string(s : String) -> ( Vec<u32>, Vec<u32> ) {
|
|
||||||
s.split("\n").filter_map(parse_line).unzip()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_line(s : &str) -> Option<( u32, u32 )> {
|
|
||||||
let (left, right) = s.trim().split_once(" ")?;
|
|
||||||
|
|
||||||
Some(( utils::str_to_u32(left)?, utils::str_to_u32(right)? ))
|
|
||||||
}
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
use crate::utils;
|
||||||
|
|
||||||
|
pub fn answer(lines : &str) -> u32 {
|
||||||
|
let ( mut left, mut right ) : ( Vec<u32>, Vec<u32> ) = lines
|
||||||
|
.split("\n")
|
||||||
|
.filter_map(parse_line)
|
||||||
|
.unzip();
|
||||||
|
|
||||||
|
left.sort_unstable();
|
||||||
|
right.sort_unstable();
|
||||||
|
|
||||||
|
left.iter()
|
||||||
|
.zip(right.iter())
|
||||||
|
.map(|(x, y)| abs_diff(&x, &y))
|
||||||
|
.sum()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn abs_diff(l : &u32, r : &u32) -> u32 {
|
||||||
|
if l >= r { l - r } else { r - l }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_line(s : &str) -> Option<( u32, u32 )> {
|
||||||
|
let (left, right) = s.trim().split_once(" ")?;
|
||||||
|
|
||||||
|
Some(( utils::str_to_u32(left)?, utils::str_to_u32(right)? ))
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
use crate::utils;
|
||||||
|
|
||||||
|
pub fn answer(s : &str) -> u32 {
|
||||||
|
let ( left, right ) : ( Vec<u32>, Vec<u32> ) = s
|
||||||
|
.split("\n")
|
||||||
|
.filter_map(parse_line)
|
||||||
|
.unzip();
|
||||||
|
|
||||||
|
left.iter()
|
||||||
|
.map(|x| right.iter().filter(|y| x == *y).count() as u32 * x)
|
||||||
|
.sum()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_line(s : &str) -> Option<( u32, u32 )> {
|
||||||
|
let (left, right) = s.trim().split_once(" ")?;
|
||||||
|
|
||||||
|
Some(( utils::str_to_u32(left)?, utils::str_to_u32(right)? ))
|
||||||
|
}
|
|
@ -1,47 +1,2 @@
|
||||||
use crate::utils;
|
pub mod part_1;
|
||||||
|
pub mod part_2;
|
||||||
pub fn answer(text : String) -> ( usize, usize ) {
|
|
||||||
let (safe, danger) : (Vec<_>, Vec<_>) = text
|
|
||||||
.split("\n")
|
|
||||||
.map(parse_line)
|
|
||||||
.partition(is_safe_line);
|
|
||||||
|
|
||||||
let total_safe = safe.len();
|
|
||||||
let total_damp : usize = danger.iter().filter(is_dampened_safe_line).count();
|
|
||||||
|
|
||||||
( total_safe, total_safe + total_damp )
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_dampened_safe_line(v : &&Vec<u8>) -> bool {
|
|
||||||
// if is_safe_line(v) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
for i in 0..v.len() {
|
|
||||||
let mut cv = v.to_vec();
|
|
||||||
cv.remove(i);
|
|
||||||
|
|
||||||
if is_safe_line(&cv) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_safe_line(v : &Vec<u8>) -> bool {
|
|
||||||
let diff : Vec<i8> = v
|
|
||||||
.windows(2)
|
|
||||||
.filter_map(|v| Some(*v.get(0)? as i8 - *v.get(1)? as i8))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let all_increasing : bool = diff.iter().all(|&x| x < 0);
|
|
||||||
let all_decreasing : bool = diff.iter().all(|&x| x > 0);
|
|
||||||
let all_bounded_ok : bool = diff.iter().all(|&x| x.abs() <= 3);
|
|
||||||
|
|
||||||
all_bounded_ok && (all_increasing || all_decreasing)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_line(s : &str) -> Vec<u8> {
|
|
||||||
s.split(" ").filter_map(utils::str_to_u8).collect()
|
|
||||||
}
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
use crate::utils;
|
||||||
|
|
||||||
|
pub fn answer(text : &str) -> usize {
|
||||||
|
text.split("\n")
|
||||||
|
.map(parse_line)
|
||||||
|
.filter(is_safe_line)
|
||||||
|
.count()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_safe_line(v : &Vec<i32>) -> bool {
|
||||||
|
let diff : Vec<i32> = v
|
||||||
|
.windows(2)
|
||||||
|
.filter_map(|v| Some(v.get(0)? - v.get(1)?))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let all_increasing : bool = diff.iter().all(|&x| x < 0);
|
||||||
|
let all_decreasing : bool = diff.iter().all(|&x| x > 0);
|
||||||
|
let all_bounded_ok : bool = diff.iter().all(|&x| x.abs() <= 3);
|
||||||
|
|
||||||
|
all_bounded_ok && (all_increasing || all_decreasing)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_line(s : &str) -> Vec<i32> {
|
||||||
|
s.split(" ").filter_map(utils::str_to_i32).collect()
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
use crate::utils;
|
||||||
|
|
||||||
|
pub fn answer(text : &str) -> usize {
|
||||||
|
text.split("\n")
|
||||||
|
.map(parse_line)
|
||||||
|
.filter(is_dampened_safe_line)
|
||||||
|
.count()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_dampened_safe_line(v : &Vec<i32>) -> bool {
|
||||||
|
if is_safe_line(v) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in 0..v.len() {
|
||||||
|
let mut cv = v.to_vec();
|
||||||
|
cv.remove(i);
|
||||||
|
|
||||||
|
if is_safe_line(&cv) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_safe_line(v : &Vec<i32>) -> bool {
|
||||||
|
let diff : Vec<i32> = v
|
||||||
|
.windows(2)
|
||||||
|
.filter_map(|v| Some(v.get(0)? - v.get(1)?))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let all_increasing : bool = diff.iter().all(|&x| x < 0);
|
||||||
|
let all_decreasing : bool = diff.iter().all(|&x| x > 0);
|
||||||
|
let all_bounded_ok : bool = diff.iter().all(|&x| x.abs() <= 3);
|
||||||
|
|
||||||
|
all_bounded_ok && (all_increasing || all_decreasing)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_line(s : &str) -> Vec<i32> {
|
||||||
|
s.split(" ").filter_map(utils::str_to_i32).collect()
|
||||||
|
}
|
||||||
|
|
|
@ -1,27 +1,2 @@
|
||||||
use crate::utils;
|
pub mod part_1;
|
||||||
use regex::Regex;
|
pub mod part_2;
|
||||||
|
|
||||||
pub fn answer(text : String) -> ( u32, u32 ) {
|
|
||||||
let re : Regex = Regex::new(r"mul\((\d{1,3}),(\d{1,3})\)").unwrap();
|
|
||||||
|
|
||||||
let (always, ignore) : (Vec<_>, Vec<_>) = text
|
|
||||||
.split("do()")
|
|
||||||
.map(|s| s.split_once("don't()").unwrap_or((s, "")))
|
|
||||||
.map(|(a, i)| ( mulsum(&re, a), mulsum(&re, i) ))
|
|
||||||
.unzip();
|
|
||||||
|
|
||||||
let a : u32 = always.iter().sum();
|
|
||||||
let i : u32 = ignore.iter().sum();
|
|
||||||
|
|
||||||
( a + i, a )
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mulsum(regx : &Regex, s : &str) -> u32 {
|
|
||||||
regx.captures_iter(s)
|
|
||||||
.map(|c| c.extract())
|
|
||||||
.filter_map(|(_, [l1, l2])| {
|
|
||||||
Some((utils::str_to_u32(l1)?, utils::str_to_u32(l2)?))
|
|
||||||
})
|
|
||||||
.map(|(x, y)| x * y)
|
|
||||||
.sum()
|
|
||||||
}
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
use crate::utils;
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
|
pub fn answer(text : &str) -> u32 {
|
||||||
|
Regex::new(r"mul\((\d{1,3}),(\d{1,3})\)")
|
||||||
|
.unwrap()
|
||||||
|
.captures_iter(text)
|
||||||
|
.map(|c| c.extract())
|
||||||
|
.filter_map(|(_, [l1, l2])| Some((utils::str_to_u32(l1)?, utils::str_to_u32(l2)?)))
|
||||||
|
.map(|(x, y)| x * y)
|
||||||
|
.sum()
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
use crate::utils;
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
|
pub fn answer(text : &str) -> u32 {
|
||||||
|
match text.split_once("don't()") {
|
||||||
|
Some((head, tail)) => {
|
||||||
|
multiplication_sum(head) + tail.split("don't()").map(take_valid).sum::<u32>()
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
multiplication_sum(text)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn take_valid(s : &str) -> u32 {
|
||||||
|
match s.split_once("do()") {
|
||||||
|
Some((_, valid)) => multiplication_sum(valid),
|
||||||
|
None => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn multiplication_sum(s : &str) -> u32 {
|
||||||
|
let re = Regex::new(r"mul\((\d{1,3}),(\d{1,3})\)").unwrap();
|
||||||
|
|
||||||
|
re.captures_iter(s)
|
||||||
|
.map(|c| c.extract())
|
||||||
|
.filter_map(|(_, [l1, l2])| Some((utils::str_to_u32(l1)?, utils::str_to_u32(l2)?)))
|
||||||
|
.map(|(x, y)| x * y)
|
||||||
|
.sum()
|
||||||
|
}
|
|
@ -1,85 +1,2 @@
|
||||||
pub fn answer(text : String) -> ( u16, u16 ) {
|
pub mod part_1;
|
||||||
let grid : Vec<Vec<char>> = from_string(text);
|
pub mod part_2;
|
||||||
|
|
||||||
let rows = grid.len();
|
|
||||||
let cols = grid[0].len();
|
|
||||||
|
|
||||||
( find_xmas(&grid, rows as isize, cols as isize), find_x_mas(&grid, rows, cols) )
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_x_mas(grid : &Vec<Vec<char>>, rows : usize, cols : usize) -> u16 {
|
|
||||||
let mut total : u16 = 0;
|
|
||||||
|
|
||||||
for y in 1..rows-1 {
|
|
||||||
for x in 1..cols-1 {
|
|
||||||
if grid[y][x] == 'A' {
|
|
||||||
total = total + inspect_x_mas_location(&grid, x, y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
total
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_xmas(grid : &Vec<Vec<char>>, rows : isize, cols : isize) -> u16 {
|
|
||||||
let mut total : u16 = 0;
|
|
||||||
|
|
||||||
for y in 0..rows {
|
|
||||||
for x in 0..cols {
|
|
||||||
if grid[y as usize][x as usize] == 'X' {
|
|
||||||
total = total + inspect_xmas_location(&grid, x, y, rows, cols)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
total
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_string(s : String) -> Vec<Vec<char>> {
|
|
||||||
s.split("\n").map(|s| s.chars().collect()).collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn inspect_x_mas_location(grid : &Vec<Vec<char>>, x : usize, y : usize) -> u16 {
|
|
||||||
let c1 = grid[y-1][x-1];
|
|
||||||
let c2 = grid[y-1][x+1];
|
|
||||||
let c3 = grid[y+1][x-1];
|
|
||||||
let c4 = grid[y+1][x+1];
|
|
||||||
|
|
||||||
let horizontal = c1 == c2 && c3 == c4 && c1 != c3;
|
|
||||||
let vertical = c1 == c3 && c2 == c4 && c1 != c2;
|
|
||||||
let letters_match = (c1 == 'M' && c4 == 'S') || (c1 == 'S' && c4 == 'M');
|
|
||||||
|
|
||||||
if letters_match && (horizontal || vertical) {
|
|
||||||
1
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn inspect_xmas_location(grid : &Vec<Vec<char>>, x : isize, y : isize, rows : isize, cols : isize) -> u16 {
|
|
||||||
let mut total : u16 = 0;
|
|
||||||
|
|
||||||
for dx in -1..=1 {
|
|
||||||
for dy in -1..=1 {
|
|
||||||
if dx == 0 && dy == 0 {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let (s_x, s_y) = ( x + 3 * dx, y + 3 * dy );
|
|
||||||
|
|
||||||
if s_x < 0 || s_x >= rows || s_y < 0 || s_y >= cols {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let m = grid[(y + 1 * dy) as usize][(x + 1 * dx) as usize];
|
|
||||||
let a = grid[(y + 2 * dy) as usize][(x + 2 * dx) as usize];
|
|
||||||
let s = grid[(y + 3 * dy) as usize][(x + 3 * dx) as usize];
|
|
||||||
|
|
||||||
if m == 'M' && a == 'A' && s == 'S' {
|
|
||||||
total = total + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
total
|
|
||||||
}
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
pub fn answer(s : &str) -> u32 {
|
||||||
|
let grid : Vec<Vec<char>> = s.split("\n")
|
||||||
|
.map(|s| s.chars().collect())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let rows : i32 = grid.len().try_into().unwrap();
|
||||||
|
let cols : i32 = grid[0].len().try_into().unwrap();
|
||||||
|
let mut total : u32 = 0;
|
||||||
|
|
||||||
|
for y in 0..rows {
|
||||||
|
for x in 0..cols {
|
||||||
|
if grid[y as usize][x as usize] == 'X' {
|
||||||
|
total = total + inspect_location(&grid, x, y, rows, cols)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
total
|
||||||
|
}
|
||||||
|
|
||||||
|
fn inspect_location(grid : &Vec<Vec<char>>, x : i32, y : i32, rows : i32, cols : i32) -> u32 {
|
||||||
|
let mut total = 0;
|
||||||
|
|
||||||
|
for dx in -1..=1 {
|
||||||
|
for dy in -1..=1 {
|
||||||
|
if dx == 0 && dy == 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let (s_x, s_y) = ( x + 3 * dx, y + 3 * dy );
|
||||||
|
|
||||||
|
if s_x < 0 || s_x >= rows || s_y < 0 || s_y >= cols {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let m = grid[(y + 1 * dy) as usize][(x + 1 * dx) as usize];
|
||||||
|
let a = grid[(y + 2 * dy) as usize][(x + 2 * dx) as usize];
|
||||||
|
let s = grid[(y + 3 * dy) as usize][(x + 3 * dx) as usize];
|
||||||
|
|
||||||
|
if m == 'M' && a == 'A' && s == 'S' {
|
||||||
|
total = total + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
total
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
pub fn answer(s : &str) -> u32 {
|
||||||
|
let grid : Vec<Vec<char>> = s.split("\n")
|
||||||
|
.map(|s| s.chars().collect())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let rows = grid.len();
|
||||||
|
let cols = grid[0].len();
|
||||||
|
let mut total : u32 = 0;
|
||||||
|
|
||||||
|
for y in 1..rows-1 {
|
||||||
|
for x in 1..cols-1 {
|
||||||
|
if grid[y as usize][x as usize] == 'A' {
|
||||||
|
total = total + inspect_location(&grid, x, y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
total
|
||||||
|
}
|
||||||
|
|
||||||
|
fn inspect_location(grid : &Vec<Vec<char>>, x : usize, y : usize) -> u32 {
|
||||||
|
let c1 = grid[y-1][x-1];
|
||||||
|
let c2 = grid[y-1][x+1];
|
||||||
|
let c3 = grid[y+1][x-1];
|
||||||
|
let c4 = grid[y+1][x+1];
|
||||||
|
|
||||||
|
let horizontal = c1 == c2 && c3 == c4 && c1 != c3;
|
||||||
|
let vertical = c1 == c3 && c2 == c4 && c1 != c2;
|
||||||
|
let letters_match = (c1 == 'M' && c4 == 'S') || (c1 == 'S' && c4 == 'M');
|
||||||
|
|
||||||
|
if letters_match && (horizontal || vertical) {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,93 +1,2 @@
|
||||||
use crate::utils;
|
pub mod part_1;
|
||||||
use std::collections::HashSet;
|
pub mod part_2;
|
||||||
|
|
||||||
type HandBook = Vec<u8>;
|
|
||||||
type RuleSet = HashSet<(u8, u8)>;
|
|
||||||
|
|
||||||
pub fn answer(text : String) -> ( u16, u16 ) {
|
|
||||||
let ( rules, handbooks ) : ( RuleSet, Vec<HandBook> ) = parse_input(text);
|
|
||||||
let ( sorted, unsorted ) : ( Vec<_>, Vec<_> ) = handbooks
|
|
||||||
.iter()
|
|
||||||
.partition(|hb| follows_rules(hb, &rules));
|
|
||||||
|
|
||||||
( sorted.iter().map(|hb| sorted_middle_value(hb) as u16).sum()
|
|
||||||
, unsorted.iter().map(|hb| unsorted_middle_value(hb, &rules)).sum()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn follows_rules(handbook : &HandBook, rules : &RuleSet) -> bool {
|
|
||||||
handbook.windows(2).all(|rule| {
|
|
||||||
match (rule.get(0), rule.get(1)) {
|
|
||||||
(Some(a), Some(b)) => {
|
|
||||||
rules.contains(&(*a, *b))
|
|
||||||
},
|
|
||||||
// Invalid situations
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_hand_line(s : &str) -> Option<Vec<u8>> {
|
|
||||||
let v : Vec<u8> = s.split(",").filter_map(utils::str_to_u8).collect();
|
|
||||||
|
|
||||||
if v.len() == 0 { None } else { Some(v) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_input(s : String) -> (RuleSet, Vec<HandBook>) {
|
|
||||||
let (r, h) = s.split_once("\n\n").unwrap_or(("", ""));
|
|
||||||
|
|
||||||
( r.split("\n").filter_map(parse_rule_line).collect()
|
|
||||||
, h.split("\n").filter_map(parse_hand_line).collect()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_rule_line(s : &str) -> Option<(u8, u8)> {
|
|
||||||
let (l, r) = s.split_once("|")?;
|
|
||||||
|
|
||||||
Some(( utils::str_to_u8(l)?, utils::str_to_u8(r)? ))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unsorted_middle_value(handbook : &HandBook, rules : &RuleSet) -> u16 {
|
|
||||||
let (head, tail) = handbook.split_first().unwrap();
|
|
||||||
|
|
||||||
let mut cursor : u8 = *head;
|
|
||||||
let mut num_lower : u8 = 0;
|
|
||||||
let mut num_higher : u8 = 0;
|
|
||||||
let mut lower : Vec<u8> = Vec::new();
|
|
||||||
let mut higher : Vec<u8> = Vec::new();
|
|
||||||
let mut stack : Vec<u8> = Vec::from(tail);
|
|
||||||
|
|
||||||
loop {
|
|
||||||
// Classify numbers based on their order
|
|
||||||
while let Some(n) = stack.pop() {
|
|
||||||
if rules.contains(&( cursor, n )) {
|
|
||||||
higher.push(n);
|
|
||||||
} else {
|
|
||||||
lower.push(n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if we've found the correct number
|
|
||||||
let low = num_lower + lower.len() as u8;
|
|
||||||
let high = num_higher + higher.len() as u8;
|
|
||||||
if low == high {
|
|
||||||
return cursor.into();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, rearrange the variables for the next step
|
|
||||||
if low < high {
|
|
||||||
(num_lower, lower) = (low + 1, Vec::new());
|
|
||||||
(stack, higher) = (higher, Vec::new());
|
|
||||||
} else {
|
|
||||||
(num_higher, higher) = (high + 1, Vec::new());
|
|
||||||
(stack, lower) = (lower, Vec::new());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pick the next value
|
|
||||||
cursor = stack.pop().unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sorted_middle_value(handbook : &HandBook) -> u8 {
|
|
||||||
handbook[handbook.len() / 2]
|
|
||||||
}
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
use crate::utils;
|
||||||
|
|
||||||
|
type HandBook = Vec<u32>;
|
||||||
|
type RuleSet = Vec<(u32, u32)>;
|
||||||
|
|
||||||
|
pub fn answer(s : &str) -> u32 {
|
||||||
|
let ( rules, handbooks ) = parse_input(s);
|
||||||
|
|
||||||
|
handbooks.iter()
|
||||||
|
.filter(|hb| follows_rules(hb, &rules))
|
||||||
|
.map(middle_value)
|
||||||
|
.sum()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn follows_rules(handbook : &HandBook, rules : &RuleSet) -> bool {
|
||||||
|
rules.iter().all(|rule| follows_rule(handbook, rule))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn follows_rule(handbook : &HandBook, (first, second) : &(u32, u32)) -> bool {
|
||||||
|
let mut encountered_second : bool = false;
|
||||||
|
|
||||||
|
for num in handbook.iter() {
|
||||||
|
if num == first {
|
||||||
|
return !encountered_second;
|
||||||
|
} else if num == second {
|
||||||
|
encountered_second = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn middle_value(handbook : &HandBook) -> u32 {
|
||||||
|
handbook[handbook.len() / 2]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_hand_line(s : &str) -> Option<Vec<u32>> {
|
||||||
|
let v : Vec<u32> = s.split(",").filter_map(utils::str_to_u32).collect();
|
||||||
|
|
||||||
|
if v.len() == 0 { None } else { Some(v) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_input(s : &str) -> (RuleSet, Vec<HandBook>) {
|
||||||
|
let (r, h) = s.split_once("\n\n").unwrap_or(("", ""));
|
||||||
|
|
||||||
|
( r.split("\n").filter_map(parse_rule_line).collect()
|
||||||
|
, h.split("\n").filter_map(parse_hand_line).collect()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_rule_line(s : &str) -> Option<(u32, u32)> {
|
||||||
|
let (l, r) = s.split_once("|")?;
|
||||||
|
|
||||||
|
Some(( utils::str_to_u32(l)?, utils::str_to_u32(r)? ))
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
use crate::utils;
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
|
type HandBook = Vec<u32>;
|
||||||
|
type RuleSet = Vec<(u32, u32)>;
|
||||||
|
|
||||||
|
pub fn answer(s : &str) -> u32 {
|
||||||
|
let ( rules, mut handbooks ) = parse_input(s);
|
||||||
|
|
||||||
|
handbooks.iter_mut()
|
||||||
|
.filter(|hb| !follows_rules(hb, &rules))
|
||||||
|
.map(|hb| { reorder_pages(hb, &rules); middle_value(hb) })
|
||||||
|
.sum()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn page_cmp(a : &u32, b : &u32, rules : &RuleSet) -> Ordering {
|
||||||
|
for (r1, r2) in rules.iter() {
|
||||||
|
if r1 == a && r2 == b {
|
||||||
|
return Ordering::Less;
|
||||||
|
} else if r1 == b && r2 == a {
|
||||||
|
return Ordering::Greater;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ordering::Equal
|
||||||
|
}
|
||||||
|
|
||||||
|
fn follows_rules(handbook : &HandBook, rules : &RuleSet) -> bool {
|
||||||
|
rules.iter().all(|rule| follows_rule(handbook, rule))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn follows_rule(handbook : &HandBook, (first, second) : &(u32, u32)) -> bool {
|
||||||
|
let mut encountered_second : bool = false;
|
||||||
|
|
||||||
|
for num in handbook.iter() {
|
||||||
|
if num == first {
|
||||||
|
return !encountered_second;
|
||||||
|
} else if num == second {
|
||||||
|
encountered_second = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn middle_value(handbook : &HandBook) -> u32 {
|
||||||
|
handbook[handbook.len() / 2]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_hand_line(s : &str) -> Option<Vec<u32>> {
|
||||||
|
let v : Vec<u32> = s.split(",").filter_map(utils::str_to_u32).collect();
|
||||||
|
|
||||||
|
if v.len() == 0 { None } else { Some(v) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_input(s : &str) -> (RuleSet, Vec<HandBook>) {
|
||||||
|
let (r, h) = s.split_once("\n\n").unwrap_or(("", ""));
|
||||||
|
|
||||||
|
( r.split("\n").filter_map(parse_rule_line).collect()
|
||||||
|
, h.split("\n").filter_map(parse_hand_line).collect()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_rule_line(s : &str) -> Option<(u32, u32)> {
|
||||||
|
let (l, r) = s.split_once("|")?;
|
||||||
|
|
||||||
|
Some(( utils::str_to_u32(l)?, utils::str_to_u32(r)? ))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reorder_pages(handbook : &mut HandBook, rules : &RuleSet) {
|
||||||
|
handbook.sort_unstable_by(|a, b| page_cmp(a, b, rules));
|
||||||
|
}
|
|
@ -1,85 +0,0 @@
|
||||||
use crate::utils;
|
|
||||||
|
|
||||||
struct Equation {
|
|
||||||
test_value : u64,
|
|
||||||
numbers : Vec<u64>
|
|
||||||
}
|
|
||||||
impl Equation {
|
|
||||||
fn from_line(s : &str) -> Option<Equation> {
|
|
||||||
let (test_value, numbers) = s.split_once(": ")?;
|
|
||||||
|
|
||||||
Some(Equation {
|
|
||||||
test_value : utils::str_to_u64(test_value)?,
|
|
||||||
numbers : numbers.split(" ").filter_map(utils::str_to_u64).collect()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn computes(&self) -> ( Option<u64>, Option<u64> ) {
|
|
||||||
let (a, b) = computes_somehow(&self.test_value, &self.numbers[..]);
|
|
||||||
|
|
||||||
( if a { Some(self.test_value) } else { None }
|
|
||||||
, if b { Some(self.test_value) } else { None }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn answer(text : String) -> ( u64, u64 ) {
|
|
||||||
let ( always, with_appends ) : ( Vec<_>, Vec<_> ) = text
|
|
||||||
.split("\n")
|
|
||||||
.filter_map(Equation::from_line)
|
|
||||||
.map(|e| e.computes())
|
|
||||||
.unzip();
|
|
||||||
|
|
||||||
( always.iter().filter_map(|x| *x).sum()
|
|
||||||
, with_appends.iter().filter_map(|x| *x).sum()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn computes_somehow(test_value : &u64, numbers : &[u64]) -> ( bool, bool ) {
|
|
||||||
if numbers.len() == 1 {
|
|
||||||
let b = *test_value == numbers[0];
|
|
||||||
( b, b )
|
|
||||||
} else if *test_value < numbers[0] {
|
|
||||||
( false, false )
|
|
||||||
} else if let Some(( &last, init )) = numbers.split_last() {
|
|
||||||
let mut with_appends : bool = false;
|
|
||||||
|
|
||||||
if test_value % last == 0 {
|
|
||||||
let (always, w) = computes_somehow(&(test_value / last), init);
|
|
||||||
with_appends = with_appends || w;
|
|
||||||
|
|
||||||
if always {
|
|
||||||
return ( true, true );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if *test_value > last {
|
|
||||||
let (always, w) = computes_somehow(&(test_value - last), init);
|
|
||||||
with_appends = with_appends || w;
|
|
||||||
|
|
||||||
if always {
|
|
||||||
return ( true, true );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
( false, with_appends || computes_with_appends(test_value, &last, init) )
|
|
||||||
} else {
|
|
||||||
( false, false )
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn computes_with_appends(big : &u64, small : &u64, numbers : &[u64]) -> bool {
|
|
||||||
let b : String = big.to_string();
|
|
||||||
let s : String = small.to_string();
|
|
||||||
|
|
||||||
if !b.ends_with(&s) {
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
let w = b.len() - s.len();
|
|
||||||
match b.get(..w).and_then(utils::str_to_u64) {
|
|
||||||
None => false,
|
|
||||||
Some(m) => {
|
|
||||||
let (_, w) = computes_somehow(&m, numbers);
|
|
||||||
w
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
use std::cmp;
|
|
||||||
use std::collections::{ HashMap, HashSet };
|
|
||||||
|
|
||||||
const WIDTH : isize = 50;
|
|
||||||
const HEIGHT : isize = 50;
|
|
||||||
|
|
||||||
pub fn answer(text : String) -> ( usize, usize ) {
|
|
||||||
let g : Grid = Grid::from(text);
|
|
||||||
|
|
||||||
( g.p1_antinodes.len(), g.p2_antinodes.len() )
|
|
||||||
}
|
|
||||||
|
|
||||||
type Coord = isize;
|
|
||||||
type Pos = (Coord, Coord);
|
|
||||||
|
|
||||||
struct Grid {
|
|
||||||
height : isize,
|
|
||||||
items : HashMap<char, HashSet<Pos>>,
|
|
||||||
p1_antinodes : HashSet<Pos>,
|
|
||||||
p2_antinodes : HashSet<Pos>,
|
|
||||||
width : isize,
|
|
||||||
}
|
|
||||||
impl Grid {
|
|
||||||
fn from(text : String) -> Grid {
|
|
||||||
let mut g = Grid::new();
|
|
||||||
|
|
||||||
for (y, line) in text.split('\n').enumerate() {
|
|
||||||
g.height = (y + 1) as isize;
|
|
||||||
g.width = cmp::max(g.width, line.len() as isize);
|
|
||||||
|
|
||||||
for (x, c) in line.chars().enumerate() {
|
|
||||||
if c != '.' {
|
|
||||||
g.insert(c, x as Coord, y as Coord);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g
|
|
||||||
}
|
|
||||||
|
|
||||||
fn insert(&mut self, c : char, x : Coord, y : Coord) {
|
|
||||||
match self.items.get(&c) {
|
|
||||||
Some(antennae) => {
|
|
||||||
for ( ax, ay ) in antennae.iter() {
|
|
||||||
let antinodes_1 = find_antinode(ax, ay, &x, &y);
|
|
||||||
let antinodes_2 = find_antinode(&x, &y, ax, ay);
|
|
||||||
|
|
||||||
if antinodes_1.len() > 1 {
|
|
||||||
self.p1_antinodes.insert(antinodes_1[1]);
|
|
||||||
}
|
|
||||||
if antinodes_2.len() > 1 {
|
|
||||||
self.p1_antinodes.insert(antinodes_2[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for pos in antinodes_1.iter().chain(antinodes_2.iter()) {
|
|
||||||
self.p2_antinodes.insert(*pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
self.items
|
|
||||||
.entry(c)
|
|
||||||
.and_modify(|h| { h.insert((x, y)); })
|
|
||||||
.or_insert(HashSet::from([ (x, y) ]));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn insert_antinodes(&mut self, antinodes : Vec<Pos>) {
|
|
||||||
match antinodes.first() {
|
|
||||||
Some(head) => { self.p1_antinodes.insert(*head); },
|
|
||||||
None => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
for pos in antinodes.iter() {
|
|
||||||
self.p2_antinodes.insert(*pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn new() -> Grid {
|
|
||||||
Grid{
|
|
||||||
height : 0,
|
|
||||||
items : HashMap::new(),
|
|
||||||
p1_antinodes : HashSet::new(),
|
|
||||||
p2_antinodes : HashSet::new(),
|
|
||||||
width : 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_antinode(x1 : &Coord, y1 : &Coord, x2 : &Coord, y2 : &Coord) -> Vec<Pos> {
|
|
||||||
let x_diff = x2 - x1;
|
|
||||||
let y_diff = y2 - y1;
|
|
||||||
|
|
||||||
let mut v = Vec::new();
|
|
||||||
|
|
||||||
for i in 1..50 {
|
|
||||||
let ax = x1 + i * x_diff;
|
|
||||||
let ay = y1 + i * y_diff;
|
|
||||||
|
|
||||||
if ax < 0 || ax >= WIDTH || ay < 0 || ay >= HEIGHT {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
v.push((ax, ay));
|
|
||||||
}
|
|
||||||
|
|
||||||
v
|
|
||||||
}
|
|
|
@ -1,194 +0,0 @@
|
||||||
use crate::utils;
|
|
||||||
use std::cmp;
|
|
||||||
|
|
||||||
pub fn answer(text : String) -> ( u64, u64 ) {
|
|
||||||
let disk : Vec<u64> = parse_input(text);
|
|
||||||
|
|
||||||
( calculate_fragmented_checksum(&disk)
|
|
||||||
, calculate_reallocated_checksum(&disk)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The Allocation struct defines a space in memory where either a file is
|
|
||||||
allocated, or where there is room to place a new file.
|
|
||||||
*/
|
|
||||||
struct Allocation {
|
|
||||||
offset : u64,
|
|
||||||
size : u64
|
|
||||||
}
|
|
||||||
impl Allocation {
|
|
||||||
/** Checksum of an allocation. Make sure to multiply by the file id.
|
|
||||||
*/
|
|
||||||
fn checksum(&self) -> u64 {
|
|
||||||
let ( a, b ) = ( self.offset, self.offset + self.size );
|
|
||||||
(a..b).sum()
|
|
||||||
}
|
|
||||||
|
|
||||||
/** If you wish to store more than one item in this allocated space, you can
|
|
||||||
use this function to split this allocated space into two.
|
|
||||||
*/
|
|
||||||
fn split(&self, size : u64) -> Option<(Allocation, Allocation)> {
|
|
||||||
if size > self.size {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some((
|
|
||||||
Allocation{ offset : self.offset, size : size },
|
|
||||||
Allocation{ offset : self.offset + size, size : self.size - size }
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Allocator{
|
|
||||||
allocs : Vec<Allocation>,
|
|
||||||
files : Vec<Allocation>,
|
|
||||||
next_cursor : u64,
|
|
||||||
next_is_file : bool,
|
|
||||||
}
|
|
||||||
impl Allocator {
|
|
||||||
fn falloc(&mut self, size : u64) -> Option<Allocation> {
|
|
||||||
for (i, a) in self.allocs.iter().enumerate() {
|
|
||||||
if let Some((alloc, rest)) = a.split(size) {
|
|
||||||
self.allocs[i] = rest;
|
|
||||||
return Some(alloc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from(s : &str) -> Allocator {
|
|
||||||
let mut allocator = Allocator::new(s.len() as u64);
|
|
||||||
|
|
||||||
for digit in s.chars().filter_map(utils::char_to_u64) {
|
|
||||||
allocator.insert(digit);
|
|
||||||
}
|
|
||||||
|
|
||||||
allocator
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_disk(disk : &Vec<u64>) -> Allocator {
|
|
||||||
let mut allocator = Allocator::new(disk.len() as u64);
|
|
||||||
|
|
||||||
for digit in disk.iter() {
|
|
||||||
allocator.insert(*digit);
|
|
||||||
}
|
|
||||||
|
|
||||||
allocator
|
|
||||||
}
|
|
||||||
|
|
||||||
fn insert(&mut self, size : u64) {
|
|
||||||
let a = Allocation{ offset : self.next_cursor, size : size };
|
|
||||||
|
|
||||||
if self.next_is_file {
|
|
||||||
self.files.push(a);
|
|
||||||
} else {
|
|
||||||
self.allocs.push(a);
|
|
||||||
}
|
|
||||||
self.next_cursor = self.next_cursor + size;
|
|
||||||
self.next_is_file = !self.next_is_file;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn new(length : u64) -> Allocator {
|
|
||||||
Allocator{
|
|
||||||
allocs : Vec::with_capacity((length / 2) as usize),
|
|
||||||
files : Vec::with_capacity((length / 2 + 1) as usize),
|
|
||||||
next_cursor : 0,
|
|
||||||
next_is_file : true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Return a list (in reverse order!) of all the files, moved to a new spot
|
|
||||||
*/
|
|
||||||
fn reorder(&mut self) -> Vec<Allocation> {
|
|
||||||
let mut out = Vec::with_capacity(self.files.len());
|
|
||||||
let mut only_move_under : u64 = 10;
|
|
||||||
|
|
||||||
while let Some(alloc) = self.files.pop() {
|
|
||||||
if alloc.size >= only_move_under {
|
|
||||||
out.push(alloc);
|
|
||||||
}
|
|
||||||
else if let Some(nalloc) = self.falloc(alloc.size) {
|
|
||||||
if alloc.offset < nalloc.offset {
|
|
||||||
out.push(alloc);
|
|
||||||
} else {
|
|
||||||
out.push(nalloc);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
only_move_under = cmp::min(only_move_under, alloc.size );
|
|
||||||
out.push(alloc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn calculate_fragmented_checksum(disk : &Vec<u64>) -> u64 {
|
|
||||||
let mut checksum : u64 = 0;
|
|
||||||
let mut disk_cursor = 0;
|
|
||||||
|
|
||||||
let mut front_cursor = 0;
|
|
||||||
let mut back_cursor = disk.len() - 1;
|
|
||||||
if back_cursor % 2 == 1 { back_cursor = back_cursor - 1; }
|
|
||||||
let mut front : FileCursor = FileCursor::File(disk[front_cursor as usize]);
|
|
||||||
let mut back : u64 = disk[back_cursor as usize];
|
|
||||||
|
|
||||||
while front_cursor <= back_cursor {
|
|
||||||
match front {
|
|
||||||
FileCursor::Empty(n) => {
|
|
||||||
if n == 0 {
|
|
||||||
front_cursor = front_cursor + 1;
|
|
||||||
if front_cursor == back_cursor {
|
|
||||||
front = FileCursor::File(back);
|
|
||||||
} else {
|
|
||||||
front = FileCursor::File(disk[front_cursor as usize]);
|
|
||||||
}
|
|
||||||
} else if back == 0 {
|
|
||||||
back_cursor = back_cursor - 2;
|
|
||||||
back = disk[back_cursor as usize];
|
|
||||||
} else {
|
|
||||||
checksum = checksum + disk_cursor * (back_cursor as u64 / 2);
|
|
||||||
disk_cursor = disk_cursor + 1;
|
|
||||||
front = FileCursor::Empty(n - 1);
|
|
||||||
back = back - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FileCursor::File(n) => {
|
|
||||||
if n == 0 {
|
|
||||||
front_cursor = front_cursor + 1;
|
|
||||||
front = FileCursor::Empty(disk[front_cursor as usize]);
|
|
||||||
} else {
|
|
||||||
checksum = checksum + disk_cursor * (front_cursor as u64 / 2);
|
|
||||||
disk_cursor = disk_cursor + 1;
|
|
||||||
front = FileCursor::File(n - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
checksum
|
|
||||||
}
|
|
||||||
|
|
||||||
fn calculate_reallocated_checksum(disk : &Vec<u64>) -> u64 {
|
|
||||||
let files = Allocator::from_disk(disk).reorder();
|
|
||||||
let size = files.len() as u64;
|
|
||||||
files.iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(i, alloc)| {
|
|
||||||
let file = size - 1 - (i as u64);
|
|
||||||
|
|
||||||
// println!("FILE: {file}, Offset: {}, Size: {}, Checksum: {}", alloc.offset, alloc.size, alloc.checksum());
|
|
||||||
|
|
||||||
file * alloc.checksum()
|
|
||||||
})
|
|
||||||
.sum()
|
|
||||||
}
|
|
||||||
|
|
||||||
enum FileCursor {
|
|
||||||
Empty(u64),
|
|
||||||
File(u64)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_input(s : String) -> Vec<u64> {
|
|
||||||
s.chars().filter_map(utils::char_to_u64).collect()
|
|
||||||
}
|
|
|
@ -1,105 +0,0 @@
|
||||||
use crate::utils;
|
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
type Coord = i8;
|
|
||||||
type Coords = ( Coord, Coord );
|
|
||||||
type Count = u16;
|
|
||||||
type Height = u8;
|
|
||||||
type Trails = Vec<Coords>;
|
|
||||||
|
|
||||||
pub fn answer(text : String) -> ( Count, Count ) {
|
|
||||||
let grid : Grid = Grid::from(text);
|
|
||||||
let ( mut p1, mut p2 ) : ( Count, Count ) = ( 0, 0 );
|
|
||||||
|
|
||||||
for (y, line) in grid.items.iter().enumerate() {
|
|
||||||
for (x, _) in line.iter().enumerate() {
|
|
||||||
let ( score, unique ) = grid.trail_maps_from(&(x as Coord), &(y as Coord));
|
|
||||||
|
|
||||||
p1 = p1 + unique;
|
|
||||||
p2 = p2 + score;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
( p1, p2 )
|
|
||||||
}
|
|
||||||
|
|
||||||
fn char_to_height(s : char) -> Option<Height> {
|
|
||||||
s.to_string().parse::<Height>().ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Grid {
|
|
||||||
items : Vec<Vec<Option<Height>>>
|
|
||||||
}
|
|
||||||
impl Grid {
|
|
||||||
fn all_neighbours_of_height(&self, height : Height, nodes : Trails) -> Trails {
|
|
||||||
nodes.iter()
|
|
||||||
.flat_map(|(x, y)| self.neighbours_of_height(height, *x, *y))
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from(s : String) -> Grid {
|
|
||||||
Grid {
|
|
||||||
items : s.split("\n")
|
|
||||||
.map(|line| line.chars().map(char_to_height).collect())
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get(&self, x : &Coord, y : &Coord) -> Option<Height> {
|
|
||||||
if *x < 0 || *y < 0 {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
self.items
|
|
||||||
.get(*y as usize)
|
|
||||||
.and_then(|line| line.get(*x as usize))
|
|
||||||
.and_then(|a| *a)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn neighbours_of_height(&self, height : Height, x : Coord, y : Coord) -> Vec<(Coord, Coord)> {
|
|
||||||
let mut v = Vec::new();
|
|
||||||
let offsets : [ (Coord, Coord); 4 ] = [
|
|
||||||
( x - 1, y ), ( x + 1, y ), ( x, y - 1 ), ( x, y + 1 )
|
|
||||||
];
|
|
||||||
|
|
||||||
for ( x, y ) in offsets.iter() {
|
|
||||||
if let Some(h) = self.get(&x, &y) {
|
|
||||||
if h == height {
|
|
||||||
v.push(( *x, *y ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
v
|
|
||||||
}
|
|
||||||
|
|
||||||
fn trail_maps_from(&self, x : &Coord, y : &Coord) -> ( Count, Count ) {
|
|
||||||
match self.get(x, y) {
|
|
||||||
Some(h) => {
|
|
||||||
if h == 0 {
|
|
||||||
let h0 : Trails = Vec::from([ (*x, *y) ]);
|
|
||||||
let h1 : Trails = self.all_neighbours_of_height(1, h0);
|
|
||||||
let h2 : Trails = self.all_neighbours_of_height(2, h1);
|
|
||||||
let h3 : Trails = self.all_neighbours_of_height(3, h2);
|
|
||||||
let h4 : Trails = self.all_neighbours_of_height(4, h3);
|
|
||||||
let h5 : Trails = self.all_neighbours_of_height(5, h4);
|
|
||||||
let h6 : Trails = self.all_neighbours_of_height(6, h5);
|
|
||||||
let h7 : Trails = self.all_neighbours_of_height(7, h6);
|
|
||||||
let h8 : Trails = self.all_neighbours_of_height(8, h7);
|
|
||||||
let h9 : Trails = self.all_neighbours_of_height(9, h8);
|
|
||||||
|
|
||||||
let score : Count = h9.len()
|
|
||||||
.try_into().expect("Answer should be <65K");
|
|
||||||
let unique : Count = h9.iter().collect::<HashSet<_>>()
|
|
||||||
.len().try_into().expect("Answer should be <65K");
|
|
||||||
|
|
||||||
( score, unique )
|
|
||||||
|
|
||||||
} else {
|
|
||||||
( 0, 0 )
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => ( 0, 0 ),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
86
src/lib.rs
86
src/lib.rs
|
@ -1,80 +1,36 @@
|
||||||
|
mod utils;
|
||||||
mod day_01;
|
mod day_01;
|
||||||
mod day_02;
|
mod day_02;
|
||||||
mod day_03;
|
mod day_03;
|
||||||
mod day_04;
|
mod day_04;
|
||||||
mod day_05;
|
mod day_05;
|
||||||
// mod day_06;
|
|
||||||
mod day_07;
|
|
||||||
mod day_08;
|
|
||||||
mod day_09;
|
|
||||||
mod day_10;
|
|
||||||
mod utils;
|
|
||||||
|
|
||||||
use std::time::Duration;
|
pub fn day_01() {
|
||||||
use crate::utils::read_from_file;
|
let s : String = utils::read_from_file("inputs/01.txt");
|
||||||
use crate::utils::diagnostics;
|
println!("Day 01 part 1: {}", day_01::part_1::answer(s.as_str()));
|
||||||
|
println!("Day 01 part 2: {}", day_01::part_2::answer(s.as_str()));
|
||||||
type DailyOutput = ( u128, u128, Duration );
|
|
||||||
|
|
||||||
pub fn day_01() -> DailyOutput {
|
|
||||||
let s : String = read_from_file("inputs/01.txt");
|
|
||||||
let ( p1, p2, d ) = diagnostics::benchmark(s, day_01::answer);
|
|
||||||
|
|
||||||
( p1 as u128, p2 as u128, d )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn day_02() -> DailyOutput {
|
pub fn day_02() {
|
||||||
let s : String = read_from_file("inputs/02.txt");
|
let s : String = utils::read_from_file("inputs/02.txt");
|
||||||
let (p1, p2, d) = diagnostics::benchmark(s, day_02::answer);
|
println!("Day 02 part 1: {}", day_02::part_1::answer(s.as_str()));
|
||||||
|
println!("Day 02 part 2: {}", day_02::part_2::answer(s.as_str()));
|
||||||
( p1 as u128, p2 as u128, d )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn day_03() -> DailyOutput {
|
pub fn day_03() {
|
||||||
let s : String = read_from_file("inputs/03.txt");
|
let s : String = utils::read_from_file("inputs/03.txt");
|
||||||
let (p1, p2, d) = diagnostics::benchmark(s, day_03::answer);
|
println!("Day 03 part 1: {}", day_03::part_1::answer(s.as_str()));
|
||||||
|
println!("Day 03 part 2: {}", day_03::part_2::answer(s.as_str()));
|
||||||
( p1 as u128, p2 as u128, d )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn day_04() -> DailyOutput {
|
pub fn day_04() {
|
||||||
let s : String = read_from_file("inputs/04.txt");
|
let s : String = utils::read_from_file("inputs/04.txt");
|
||||||
let (p1, p2, d) = diagnostics::benchmark(s, day_04::answer);
|
println!("Day 04 part 1: {}", day_04::part_1::answer(s.as_str()));
|
||||||
|
println!("Day 04 part 2: {}", day_04::part_2::answer(s.as_str()));
|
||||||
( p1 as u128, p2 as u128, d )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn day_05() -> DailyOutput {
|
pub fn day_05() {
|
||||||
let s : String = read_from_file("inputs/05.txt");
|
let s : String = utils::read_from_file("inputs/05.txt");
|
||||||
let (p1, p2, d) = diagnostics::benchmark(s, day_05::answer);
|
println!("Day 05 part 1: {}", day_05::part_1::answer(s.as_str()));
|
||||||
|
println!("Day 05 part 2: {}", day_05::part_2::answer(s.as_str()));
|
||||||
( p1 as u128, p2 as u128, d )
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn day_07() -> DailyOutput {
|
|
||||||
let s : String = read_from_file("inputs/07.txt");
|
|
||||||
let (p1, p2, d) = diagnostics::benchmark(s, day_07::answer);
|
|
||||||
|
|
||||||
( p1 as u128, p2 as u128, d )
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn day_08() -> DailyOutput {
|
|
||||||
let s : String = read_from_file("inputs/08.txt");
|
|
||||||
let (p1, p2, d) = diagnostics::benchmark(s, day_08::answer);
|
|
||||||
|
|
||||||
( p1 as u128, p2 as u128, d )
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn day_09() -> DailyOutput {
|
|
||||||
let s : String = read_from_file("inputs/09.txt");
|
|
||||||
let (p1, p2, d) = diagnostics::benchmark(s, day_09::answer);
|
|
||||||
|
|
||||||
( p1 as u128, p2 as u128, d )
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn day_10() -> DailyOutput {
|
|
||||||
let s : String = read_from_file("inputs/10.txt");
|
|
||||||
let (p1, p2, d) = diagnostics::benchmark(s, day_10::answer);
|
|
||||||
|
|
||||||
( p1 as u128, p2 as u128, d )
|
|
||||||
}
|
}
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -1,18 +1,7 @@
|
||||||
mod utils;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut aoc = crate::utils::diagnostics::AdventOfCode::new();
|
aoc_2024::day_01();
|
||||||
|
aoc_2024::day_02();
|
||||||
aoc.insert(1, aoc_2024::day_01());
|
aoc_2024::day_03();
|
||||||
aoc.insert(2, aoc_2024::day_02());
|
aoc_2024::day_04();
|
||||||
aoc.insert(3, aoc_2024::day_03());
|
aoc_2024::day_05();
|
||||||
aoc.insert(4, aoc_2024::day_04());
|
|
||||||
aoc.insert(5, aoc_2024::day_05());
|
|
||||||
// aoc.insert(6, aoc_2024::day_06());
|
|
||||||
aoc.insert(7, aoc_2024::day_07());
|
|
||||||
aoc.insert(8, aoc_2024::day_08());
|
|
||||||
aoc.insert(9, aoc_2024::day_09());
|
|
||||||
aoc.insert(10, aoc_2024::day_10());
|
|
||||||
|
|
||||||
aoc.show_diagnostics();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,102 +0,0 @@
|
||||||
use colored::Colorize;
|
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
|
|
||||||
const MAX_MS_ON_SCREEN : u128 = 100;
|
|
||||||
const BAR_WIDTH_UNIT : f32 = 10.0;
|
|
||||||
|
|
||||||
pub struct AdventOfCode {
|
|
||||||
days : [ Option<DayResults>; 25 ],
|
|
||||||
}
|
|
||||||
impl AdventOfCode {
|
|
||||||
pub fn insert(&mut self, i : usize, (p1, p2, d ) : ( u128, u128, Duration )) {
|
|
||||||
self.days[i - 1] = Some(
|
|
||||||
DayResults{ part_1 : p1, part_2 : p2, duration : d }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new() -> AdventOfCode {
|
|
||||||
AdventOfCode{
|
|
||||||
// If I don't do it like this, the compiler wants me to define
|
|
||||||
// the Copy trait for the DayResults struct.
|
|
||||||
days : [
|
|
||||||
None, None, None, None, None,
|
|
||||||
None, None, None, None, None,
|
|
||||||
None, None, None, None, None,
|
|
||||||
None, None, None, None, None,
|
|
||||||
None, None, None, None, None,
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn show_diagnostics(&self) {
|
|
||||||
println!("| | {: ^14} | {: ^14} | Duration |",
|
|
||||||
"Part 1", "Part 2"
|
|
||||||
);
|
|
||||||
|
|
||||||
let total : u128 = self.days
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(day, result)| {
|
|
||||||
match result {
|
|
||||||
Some(r) => {
|
|
||||||
println!("{}", r.to_string(day + 1, MAX_MS_ON_SCREEN));
|
|
||||||
r.duration.as_millis()
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
println!("{}", empty_diagnostic(day + 1));
|
|
||||||
0
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.sum();
|
|
||||||
|
|
||||||
println!("");
|
|
||||||
println!("Total duration: {total} ms");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct DayResults {
|
|
||||||
part_1 : u128,
|
|
||||||
part_2 : u128,
|
|
||||||
duration : Duration,
|
|
||||||
}
|
|
||||||
impl DayResults {
|
|
||||||
fn to_string(&self, day : usize, max_duration : u128) -> String {
|
|
||||||
let duration = self.duration.as_millis();
|
|
||||||
let fraction = duration as f32 / max_duration as f32;
|
|
||||||
|
|
||||||
let g = horizontal_bar('#', ' ', 4.0 * BAR_WIDTH_UNIT * fraction, 2.0 * BAR_WIDTH_UNIT);
|
|
||||||
let o = horizontal_bar('#', ' ', 4.0 * BAR_WIDTH_UNIT * (fraction - 0.50), BAR_WIDTH_UNIT);
|
|
||||||
let r = horizontal_bar('#', ' ', 4.0 * BAR_WIDTH_UNIT * (fraction - 0.75), BAR_WIDTH_UNIT);
|
|
||||||
|
|
||||||
format!(
|
|
||||||
"| Day {: >2} | {: >14} | {: >14} | {: >6}ms | [{: <}{: <6}{: <6}",
|
|
||||||
day, self.part_1, self.part_2, self.duration.as_millis(),
|
|
||||||
g.as_str().green(), o.as_str().yellow(), r.as_str().red()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn benchmark<A,B>(s : String, f : fn(String) -> ( A, B )) -> ( A, B, Duration ) {
|
|
||||||
let now = Instant::now();
|
|
||||||
|
|
||||||
let ( a, b ) = f(s);
|
|
||||||
|
|
||||||
( a, b, now.elapsed() )
|
|
||||||
}
|
|
||||||
|
|
||||||
fn empty_diagnostic(day : usize) -> String {
|
|
||||||
format!("| Day {: >2} | {:->14} | {:->14} | {:->8} | [", day, "", "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn horizontal_bar(full : char, empty : char, width : f32, max_width : f32) -> String {
|
|
||||||
(0..(max_width.floor() as u32))
|
|
||||||
.map(|w| {
|
|
||||||
if (w as f32) < width {
|
|
||||||
full
|
|
||||||
} else {
|
|
||||||
empty
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
|
@ -1,11 +1,5 @@
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
pub mod diagnostics;
|
|
||||||
|
|
||||||
pub fn char_to_u64(s : char) -> Option<u64> {
|
|
||||||
s.to_string().parse::<u64>().ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn read_from_file(name : &str) -> String {
|
pub fn read_from_file(name : &str) -> String {
|
||||||
match fs::read_to_string(name) {
|
match fs::read_to_string(name) {
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
|
@ -19,15 +13,7 @@ pub fn read_from_file(name : &str) -> String {
|
||||||
pub fn str_to_i32(s : &str) -> Option<i32> {
|
pub fn str_to_i32(s : &str) -> Option<i32> {
|
||||||
s.trim().to_string().parse::<i32>().ok()
|
s.trim().to_string().parse::<i32>().ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn str_to_u8(s : &str) -> Option<u8> {
|
|
||||||
s.trim().to_string().parse::<u8>().ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn str_to_u32(s : &str) -> Option<u32> {
|
pub fn str_to_u32(s : &str) -> Option<u32> {
|
||||||
s.trim().to_string().parse::<u32>().ok()
|
s.trim().to_string().parse::<u32>().ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn str_to_u64(s : &str) -> Option<u64> {
|
|
||||||
s.trim().to_string().parse::<u64>().ok()
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue