diff --git a/y2024/resources/7_input.txt b/y2024/resources/7_input.txt new file mode 100644 index 0000000..138951b --- /dev/null +++ b/y2024/resources/7_input.txt @@ -0,0 +1,850 @@ +27905293: 1 3 67 91 5 5 293 +2656278: 383 3 7 99 1 8 +5824995: 5 1 8 2 1 89 1 6 4 2 47 3 +777381126: 9 749 93 7 31 8 4 2 1 5 6 +1315092: 3 29 76 4 46 83 6 +1746: 680 675 375 9 7 +3811598532: 17 1 60 697 7 35 7 6 6 7 +1698008: 2 5 63 5 81 47 86 +3308151: 8 367 1 33 36 9 2 59 3 7 +304128: 8 44 864 +271358: 1 1 4 1 8 5 3 7 35 53 35 +2822415: 658 1 2 1 683 7 300 7 8 +151115404843801: 616 5 62 9 225 76 578 +10594914304: 4 88 844 533 256 +137763: 1 7 123 16 3 +957305: 90 408 30 66 26 89 +11046: 83 9 40 3 6 +4055108: 584 289 929 5 5 +517632: 191 820 8 8 8 +58113832155: 23 95 9 7 781 1 5 969 +138631373: 19 1 1 912 922 8 +29300652: 59 66 930 28 628 9 +4910830: 613 8 6 1 830 +432310: 199 5 2 6 1 5 8 5 1 1 17 5 +1692639962: 7 3 85 9 33 76 3 8 996 2 +1051087603: 20 689 2 499 760 2 5 3 +132193862: 5 47 99 79 501 2 +10468: 443 651 3 930 1 5 333 +225: 17 8 7 2 48 +8849850: 884 96 2 48 2 +7998370616: 9 3 3 932 457 856 77 6 +197685: 625 7 5 90 9 +23362468: 53 5 76 53 68 +146418: 83 580 665 3 2 1 +80662: 29 4 31 3 2 7 4 82 49 6 2 +86857594: 8 674 4 70 9 34 593 1 +29621764: 5 447 6 93 7 8 5 4 6 8 1 4 +62943216: 49 79 1 1 83 592 +263797648: 8 7 90 3 3 3 4 2 5 6 4 9 +106637574552: 8 6 8 9 7 1 2 6 96 819 8 +31539503114: 9 2 41 8 6 3 88 874 +44281: 14 53 66 8 29 +627: 2 9 60 8 3 +7986693: 387 737 1 28 561 +61698: 70 4 2 5 941 5 1 4 5 6 2 7 +4065686352: 528 77 858 11 544 +111069384: 6 723 758 3 6 67 +110111: 7 650 4 6 911 +48258: 7 23 3 46 1 619 66 2 7 9 +186553437: 12 955 10 18 8 +20190745: 1 9 343 2 19 3 43 8 9 +14450403260: 29 983 2 567 85 1 16 +2309768370: 225 179 7 98 90 91 +1606331569716: 5 568 3 538 56 7 93 6 +11725: 854 51 264 3 8 +102771365: 223 3 95 116 12 23 1 8 +644732: 86 8 6 929 6 +44043274814: 944 90 6 8 2 8 4 9 3 1 3 9 +23433: 5 2 42 2 139 2 8 41 8 7 7 +2543688: 2 309 7 7 84 +12624245: 5 574 4 36 4 5 2 6 424 5 +294110: 5 474 614 4 1 +12960696: 61 2 49 8 6 7 2 5 9 428 3 +49735: 4 608 8 1 774 +24927276192: 263 7 59 290 8 58 78 +5671488: 77 766 96 2 48 +6620: 92 7 390 20 13 +470191854: 59 754 34 123 47 +3798480: 8 43 1 4 4 46 146 665 +55957973060: 3 3 64 7 8 1 2 63 1 9 58 +1516: 6 682 828 1 +122967: 3 6 1 44 8 1 724 67 +436407154: 25 5 931 25 3 18 5 5 +1552941: 24 647 45 5 90 1 +4341530601: 156 6 1 453 4 7 90 9 17 +64528843: 94 893 2 34 34 125 5 8 +14176705232: 4 97 685 889 6 3 1 5 1 2 +477175854523: 592 14 2 73 133 3 83 +1506816: 5 64 76 9 24 +1108966: 158 33 2 58 5 +53886806512: 5 4 6 7 1 2 8 49 8 2 77 8 +10564: 2 137 4 19 1 +14965861605: 864 632 584 2 16 2 1 5 +1744751: 9 7 273 3 7 74 21 6 19 +310301175: 306 73 281 331 33 4 9 +56733603: 30 70 28 66 3 +14200304: 22 49 257 585 2 8 6 74 +2058562: 5 219 6 327 13 7 8 +55940568098: 931 8 8 46 28 60 98 +367211289881: 992 517 93 716 1 +171: 56 3 3 +68135804: 859 8 708 111 8 +19576263: 21 7 1 9 37 263 +29648: 2 96 4 8 +115798: 39 29 4 22 98 1 +284294885: 170 4 3 959 60 62 21 7 +1387776767: 8 18 56 96 765 +516468: 5 16 46 5 3 +64989: 4 6 32 3 83 +7703: 836 8 97 2 3 29 884 +2593692364: 431 2 3 427 8 7 6 668 +67323: 5 119 13 28 748 +650573172008: 169 86 24 470 383 +359664: 80 5 2 32 88 1 7 8 7 2 1 1 +3057397: 4 83 633 3 4 +127259832457: 1 755 1 499 84 2 457 +4237026: 9 2 58 4 8 2 3 51 2 22 2 6 +10830240: 54 54 591 9 88 7 5 960 +1617: 15 107 6 6 +2420840404: 763 9 3 7 4 9 8 8 3 44 1 2 +14890230: 2 49 485 503 310 +251591: 8 7 14 974 8 632 28 39 +1748935814: 7 347 3 22 5 6 6 6 9 8 9 5 +8849341: 758 26 1 449 +2067721: 485 1 88 2 6 4 5 2 60 1 +188944: 99 3 764 8 4 2 3 2 9 3 49 +13561782: 5 5 1 5 8 3 77 3 3 627 7 8 +259593: 1 2 2 3 1 8 9 4 92 507 8 1 +7419051443: 6 4 8 8 24 119 1 4 2 9 3 4 +2193864: 19 2 4 23 3 864 +157860: 8 8 360 3 5 1 5 3 2 9 60 1 +735258079483: 227 8 81 45 46 717 +1397845: 6 908 1 2 22 98 689 2 4 +27164919: 9 8 95 7 4 61 1 65 639 +9617797: 28 5 2 3 9 8 1 5 8 91 3 7 +100267221822: 6 33 93 6 6 1 9 720 3 2 7 +1899738: 8 6 4 1 5 3 71 5 257 1 8 +788: 4 7 64 4 709 +5498294599: 7 3 1 743 935 8 9 9 83 9 +705: 696 8 1 +1321530: 89 7 40 9 6 5 50 988 7 5 +2907: 51 5 37 170 665 +36677522025: 1 8 9 1 2 6 1 69 3 3 6 593 +488609631430: 86 326 7 9 566 27 +25363583907: 2 38 99 922 907 9 9 6 +21215: 7 47 56 7 42 5 +124533200: 4 5 4 7 8 6 9 913 620 1 2 +664025757: 8 3 1 7 568 1 8 7 8 1 1 57 +58480049: 1 4 7 3 32 1 4 23 29 882 +9718953216: 953 4 7 813 448 +5959367270: 9 92 727 29 99 +64885475: 2 2 2 1 466 9 573 3 101 +101581: 5 1 7 7 4 7 66 19 6 3 3 85 +573594: 4 9 3 64 7 8 6 4 7 13 5 42 +3872278848: 766 94 506 41 45 +1518518570: 4 134 4 8 708 3 8 10 60 +95359660: 617 50 24 851 7 4 +328296: 122 32 14 60 6 +6086: 1 8 8 353 8 8 8 2 1 71 62 +5686734: 8 9 77 724 5 2 56 8 1 6 6 +91728244: 917 282 44 +265091: 5 7 3 6 91 7 94 92 616 9 +42537077900: 3 71 773 608 73 826 +166742488: 5 9 21 3 4 6 38 652 6 1 1 +207065430: 90 73 58 4 429 9 429 5 +169143260: 880 336 25 13 44 +9409727: 905 31 1 48 727 +1830828247: 5 9 112 6 936 9 7 5 12 9 +27012357: 2 53 43 1 47 9 6 9 510 3 +636: 18 5 38 4 7 8 1 173 +10194082033: 8 43 35 80 4 58 4 5 3 3 1 +485329600: 43 5 53 29 600 +263277: 94 1 1 4 75 9 9 429 3 3 9 +4234054029: 36 2 6 370 4 9 206 6 7 +903573: 994 909 27 +7538939: 84 591 78 893 9 +402422855515: 737 886 551 45 55 15 +164268: 705 3 29 8 9 +32388: 6 302 58 2 1 22 2 88 92 +6000999669: 976 26 8 92 67 3 6 9 7 7 +9581: 5 383 5 3 3 +39886: 67 8 2 62 49 +494328620: 617 2 7 4 15 29 8 61 2 6 +441490: 7 2 85 7 53 +408601440: 7 552 286 1 138 8 438 +20555197: 995 74 836 23 465 1 +6837515448: 125 229 22 6 91 36 +54960872: 45 3 8 9 2 6 4 1 283 7 1 8 +126616: 14 9 514 60 42 +117207453600: 84 4 663 3 25 496 162 +1538: 4 6 2 3 5 6 91 587 2 3 1 +27238435993600: 793 85 8 2 335 76 992 +20667334: 36 90 2 65 40 1 28 394 +11439: 161 71 8 +2916: 18 2 926 21 5 3 +93277: 92 934 4 29 9 640 +75053: 31 60 7 4 7 618 +17972: 4 3 93 4 4 7 71 31 7 +2679: 3 17 34 1 642 +43731525: 9 22 7 790 668 47 +17227: 701 221 26 18 163 +5666750: 54 17 459 4 661 950 +1958196985: 80 993 290 9 85 220 +1203446220: 44 132 2 683 219 +33165: 2 4 9 165 +6523355997: 7 765 9 600 4 35 +198552432960: 340 643 53 34 504 +194266007: 2 3 31 7 9 4 26 5 4 2 9 5 +81637477: 78 3 1 56 92 621 61 77 +5579136: 387 949 232 6 3 +502464150: 9 919 15 5 9 2 8 8 4 3 5 3 +2419: 7 55 1 9 3 5 426 3 4 3 8 1 +179766373116: 5 4 4 3 3 7 66 9 419 6 +3439571526: 683 5 8 6 4 31 8 6 79 7 6 +79292: 43 1 901 2 4 +9781384: 155 95 6 8 83 +47172: 8 8 5 682 105 9 +316827: 93 7 9 54 7 9 252 85 88 +5583938067: 140 3 813 73 8 1 345 6 +3713632: 1 7 80 97 1 55 8 1 32 +1612682: 74 5 851 4 1 55 6 1 961 +59165553920: 7 8 97 8 3 3 4 58 6 4 605 +9838113120: 24 63 708 44 3 22 55 +3916: 6 59 2 92 3 887 629 +12385917: 479 87 33 76 928 9 +51: 29 8 6 1 8 +31010148: 3 868 5 113 7 767 9 +370693272485: 8 4 6 6 468 9 3 4 72 485 +28267096: 1 283 8 9 34 1 9 12 12 7 +1278: 9 5 3 29 18 +3848: 25 5 2 64 8 +37941: 845 3 215 894 6 905 3 +420077: 52 509 8 1 4 +734492: 9 11 7 8 91 +312542217: 791 542 9 1 1 45 9 8 9 +1054840080171: 94 18 215 2 56 168 3 +83181687076: 4 5 994 4 10 8 18 82 +1760: 293 5 70 9 216 +117725: 16 27 1 6 1 9 208 5 +2920: 5 8 2 667 4 5 83 6 7 86 5 +170679: 283 9 67 1 29 +1776762: 355 50 17 62 1 +1363805: 987 2 8 539 5 885 8 9 3 +2994922: 2 61 8 1 71 7 46 +64978320: 346 8 24 8 978 +106207: 72 28 6 147 60 +160065: 96 75 71 9 7 7 73 3 46 +21439242: 660 3 890 830 21 17 9 +5306: 38 403 1 12 2 +26360813569: 2 6 360 7 55 58 33 23 9 +5270496: 7 15 1 496 462 +14707533: 76 41 8 590 13 +12607591584: 744 9 495 5 1 604 7 8 +59935652: 524 71 3 537 8 +293059800: 8 74 6 722 825 +107802: 49 672 24 663 6 +73438429: 50 4 2 158 83 31 +12816554: 353 3 6 6 554 +219288633: 219 287 712 563 361 +13386240: 67 827 31 483 378 +432231552: 9 80 2 3 8 108 887 6 +996050214: 83 5 30 61 57 8 8 897 +1711946: 36 1 24 915 8 958 +608141: 11 98 4 562 57 +20761436: 3 16 371 5 3 105 4 383 +258724950816: 5 212 339 2 9 8 5 1 2 8 +6774: 7 6 44 2 86 +33705612: 74 9 450 52 556 1 +47099: 4 61 193 7 +99630864: 688 18 42 7 1 3 48 +14300172905: 56 409 7 169 4 362 2 4 +39539513: 50 4 2 4 66 13 247 +219296465: 679 6 3 8 4 397 25 46 +358051294: 8 5 5 20 38 4 6 302 1 94 +1542670872: 66 7 812 209 72 +83143: 20 50 83 16 127 +39731: 9 894 44 +935306790: 6 361 9 7 5 9 819 40 5 3 +67892: 6 15 8 58 115 4 +1996831838: 2 4 817 354 2 80 863 +4943769471878: 701 5 25 27 8 1 697 7 +2094768: 8 5 9 781 6 23 8 432 +1499841509: 774 9 3 78 8 715 9 300 +70082: 725 32 3 62 1 418 2 +67926144: 27 4 1 6 6 402 3 32 44 +270950403: 8 784 72 600 3 +31505774: 7 8 7 1 8 9 390 51 14 +3725925: 9 8 4 4 1 4 46 7 3 7 5 705 +18274522950: 90 203 4 52 29 51 +62066: 40 571 9 6 6 +37696: 9 69 352 5 340 28 792 +2504: 146 29 3 2 3 72 851 +50: 35 8 7 +244047: 1 8 8 8 23 728 832 7 +2571894: 910 5 8 9 8 2 2 43 5 6 39 +393543246398: 6 79 887 947 69 8 +21805135: 11 93 7 73 58 5 35 +40625413986: 677 6 54 1 325 3 726 7 +129329: 3 1 2 256 7 1 9 14 5 249 +49087845: 40 978 66 894 1 721 2 +4216656: 4 212 4 647 9 +25442241: 3 22 441 410 737 94 +1725308935: 7 6 55 6 1 6 3 9 7 576 8 7 +358416154: 2 8 2 2 7 90 41 4 1 61 5 4 +5695326: 5 6 24 94 8 19 819 +3495960: 3 61 11 9 69 3 15 312 +2346392: 313 6 4 415 2 4 37 +36979756: 231 4 493 9 4 +2323245047: 879 9 6 9 581 6 6 5 6 6 5 +922836399: 259 663 8 363 99 +385543: 4 919 9 904 2 7 9 6 6 4 3 +3605690865: 74 19 6 702 81 3 +754553: 6 3 6 568 553 +26695441: 7 5 7 6 5 2 1 6 70 7 234 +2420298: 94 260 99 38 700 +603024776: 3 39 4 9 75 51 779 +860160048: 453 47 84 8 80 8 1 6 5 4 +19072: 317 6 1 6 44 +1251666: 539 43 2 3 8 9 6 5 9 4 6 6 +14688: 9 6 139 2 46 34 +5405: 6 92 23 44 76 5 +10278040: 2 28 318 35 9 8 54 5 8 +105740464: 6 94 51 7 404 65 +163415: 761 4 37 3 7 29 +1220: 446 529 242 3 +1489672573: 5 9 89 6 71 603 969 +646837: 64 6 5 3 37 +29640891424: 807 87 644 4 91 7 424 +1231633258: 3 9 5 2 5 497 34 7 9 9 9 1 +110635274: 1 5 6 52 75 788 26 47 +34292621: 647 53 987 550 84 +1415706432: 698 331 2 7 8 74 2 1 83 +412: 41 248 27 96 +53773308: 4 9 7 6 5 8 7 44 6 9 1 522 +10322676: 96 2 808 8 631 299 4 +33766: 4 29 9 1 9 5 49 4 3 922 7 +316707973: 8 5 732 36 36 317 3 73 +239713: 7 1 4 3 65 37 532 5 2 3 1 +412616502: 39 6 914 3 114 +164080507: 23 209 93 517 76 +1147995: 9 518 6 7 9 1 5 85 1 31 +38189: 216 165 89 +1352: 2 2 338 +94848: 52 5 52 4 76 +3431: 35 94 75 64 2 +78549756: 75 243 431 6 +92185289902: 4 5 72 1 8 5 233 56 902 +298: 2 6 100 2 46 +161028: 1 3 1 555 2 9 6 6 858 3 7 +1534525: 816 4 5 94 445 +130498923: 7 156 175 4 178 1 +4583444550: 476 691 929 5 24 3 18 +232294392: 63 9 9 51 24 33 +17685502: 739 3 5 34 2 370 7 10 2 +720634: 935 2 2 1 8 8 1 103 3 5 2 +32327852: 2 463 31 95 547 6 9 1 1 +51797: 40 1 8 36 4 7 1 6 5 801 6 +140760: 2 6 2 69 85 +7438: 2 7 4 122 606 +54903: 73 741 174 595 41 +27065: 8 8 6 173 9 2 21 2 6 545 +52479: 9 8 2 49 7 5 7 9 6 8 89 38 +472357: 6 1 80 335 6 +682901: 3 29 34 7 61 33 91 4 +6885: 1 66 90 553 1 6 288 7 +263500: 7 2 54 986 250 +18820675235: 743 9 253 52 34 +23334339840: 4 1 5 956 5 8 31 4 8 123 +1188316: 8 495 90 3 45 +20504591: 201 2 2 46 3 1 7 4 2 3 9 6 +297797764214235: 297 7 97 76 421 4 235 +31726289959: 59 36 666 252 89 1 7 +171645166: 2 383 938 9 197 3 8 30 +539250093: 345 7 1 98 4 6 31 2 9 4 4 +151209: 4 6 7 5 5 7 3 84 18 5 4 +3206065541: 3 62 5 19 35 4 6 3 4 8 9 5 +43403: 16 27 1 94 9 +465630: 80 481 830 +40851: 51 9 89 +339581134: 1 675 94 578 763 354 +1287: 918 26 8 335 +563371816: 8 805 9 9 1 3 4 6 90 76 +1384644257: 138 46 35 8 8 97 360 +10150: 6 5 958 7 452 3 +269082: 885 5 82 5 9 3 7 65 480 +16754264: 89 1 502 375 5 9 +146209073461: 7 615 4 2 3 70 8 2 7 7 60 +640: 1 4 64 1 2 +138233: 4 520 22 1 8 3 75 854 +3289616284076: 60 9 1 1 8 8 3 6 9 203 9 2 +78211049650: 752 26 6 7 9 4 96 50 +641662: 71 3 619 27 14 +756121120: 5 7 5 98 893 8 3 6 88 72 +190920180: 6 9 69 55 486 89 1 22 +4417: 228 3 5 991 6 +1223602: 87 4 20 7 2 +128242248923: 93 7 54 48 6 76 92 3 +1407: 115 794 498 +5665725: 757 15 99 65 65 +649: 6 37 12 +95292: 584 368 92 +621075344751: 5 1 1 210 7 5 3 44 4 3 4 8 +78540605508: 4 3 7 4 3 5 13 2 4 550 8 +1890: 7 71 2 29 85 7 +1052: 97 4 656 1 7 +312089120: 8 39 48 3 3 344 44 5 56 +618902: 244 634 6 5 2 4 4 62 +2330433971: 364 64 2 3 3 3 395 6 6 9 +4560701: 876 30 7 503 +262: 72 54 98 1 38 +3513950211: 29 8 7 10 23 7 20 8 9 64 +131948998: 43 1 1 721 7 304 115 2 +792500: 3 4 188 7 7 46 2 4 4 2 5 5 +3906: 431 3 9 1 +8525440: 9 1 80 82 386 84 56 80 +9420: 9 5 7 1 65 1 34 36 +4556893: 7 65 68 93 +611890240500: 669 849 4 5 9 30 7 114 +15364411776: 3 7 9 8 60 9 392 12 9 4 +456237750: 8 28 32 9 44 45 750 +1081609: 8 4 62 8 34 2 34 1 +133: 28 90 3 6 6 +588127471: 715 615 600 2 737 +9506: 9 50 9 +664286544: 9 699 95 937 39 4 +4437: 4 426 8 +964: 9 58 6 +4690020: 9 17 7 7 61 7 5 1 +470716287: 46 9 729 2 587 4 976 7 +9258: 92 25 4 56 2 +50672756232: 589 204 900 792 71 +264130626: 5 2 73 7 2 118 7 7 49 2 6 +5326: 47 6 1 2 6 +6206284800: 1 3 656 54 730 80 +7307052: 4 45 9 9 91 3 76 16 8 2 +1453: 96 27 84 7 4 +2963: 98 3 3 16 +504: 4 8 6 4 +65453473950: 889 7 242 8 38 4 8 +1934525: 3 2 3 1 584 92 3 72 3 4 5 +77778517: 3 640 5 1 4 7 2 6 6 871 +25133525: 623 2 1 4 6 87 52 5 +1755293137: 7 538 8 2 6 5 8 2 1 67 5 3 +4005056: 267 10 5 11 7 3 +489: 1 9 93 8 379 +454722246: 5 6 82 7 4 36 3 5 48 5 6 1 +79547344: 88 989 914 66 30 +13099520: 5 61 4 5 3 4 7 4 2 1 5 43 +4458680: 74 7 1 58 2 167 8 681 +136160: 7 4 154 8 80 +125: 3 2 4 86 3 +52991568: 49 5 4 630 843 1 2 4 7 6 +12739979: 17 4 276 9 49 244 7 +277290067: 3 5 83 260 300 3 65 1 +99745: 996 6 1 84 +601574910: 18 42 698 1 795 +156084: 6 3 4 5 7 77 74 629 3 5 9 +117027836800: 5 184 8 115 8 560 7 5 +337590: 72 2 41 35 2 55 +14137400200467: 693 51 500 4 97 4 4 67 +1791503044: 9 622 447 4 8 1 4 +38271: 424 3 14 1 5 984 12 3 +6756: 4 538 836 26 9 2 7 703 +134593: 7 1 5 93 71 2 36 4 841 +125750882530: 6 933 8 1 93 4 5 2 8 9 7 +94930992: 11 1 94 8 4 1 7 2 408 39 +1614: 4 4 214 7 4 +2645205: 5 21 451 68 37 +120: 8 52 2 +7429: 20 4 53 5 28 3 541 +1546605578: 85 8 6 419 5 4 3 9 7 7 1 7 +5460: 6 2 6 97 7 3 7 +1623414: 6 33 9 23 247 388 5 39 +3141512: 8 615 1 4 638 +1831517: 56 8 6 681 54 935 +311326: 99 7 614 81 184 +5802827578515: 403 238 505 43 605 +773: 726 1 28 9 9 +7607050: 5 4 3 5 7 558 4 6 97 4 4 2 +4917: 48 4 2 64 7 4 +121451402: 69 696 6 70 2 21 9 2 +28864528: 42 699 2 338 4 +19491507084: 77 7 625 3 84 914 84 +6789125: 5 51 64 416 5 +43: 4 34 1 5 +12168: 335 1 34 757 21 +207655426: 207 65 460 74 7 8 7 1 +2608735203: 9 2 7 8 9 9 421 8 1 60 7 9 +636844203: 16 5 19 452 8 44 20 3 +7880787: 71 932 3 1 14 559 8 +554491547: 85 7 4 6 90 7 2 81 9 6 +1108283832: 601 674 36 18 76 +21412: 5 68 4 7 6 58 609 97 +117304660: 41 73 77 509 6 5 +14571768: 113 6 25 5 513 +13450950: 7 8 8 2 1 2 7 4 8 5 842 9 +4676209064: 8 7 3 6 58 1 9 9 4 933 +5265563525: 62 6 852 8 84 5 +3638552: 7 38 7 897 1 3 78 8 +254044056: 9 55 1 7 84 7 900 6 68 7 +105408: 17 4 627 9 8 +1793691533882: 574 90 8 906 1 39 9 4 +65565: 715 5 18 463 6 79 9 +54255702: 897 1 8 8 7 1 38 135 7 5 +1387116: 8 6 7 7 8 44 6 3 963 727 +316960839767: 387 91 871 9 766 +1782: 5 154 8 990 14 +803962: 7 901 138 6 2 +420253599: 54 9 206 257 7 2 1 9 3 1 +673728381163: 11 4 660 8 13 29 4 160 +130275: 8 68 5 416 135 +8605: 26 3 9 6 1 27 1 6 6 494 5 +9423: 93 5 2 851 9 +291: 9 236 2 44 +4925376: 6 5 9 77 8 1 93 +447661712477: 2 1 610 17 5 1 62 3 7 2 4 +11385: 166 41 55 +2396: 8 156 5 901 675 +7555485: 88 92 2 933 8 43 +98852355: 3 14 9 7 965 67 4 7 441 +45373925520: 8 4 4 6 421 1 5 396 6 6 7 +3852186680: 99 93 96 647 640 439 +516188945046: 775 7 723 78 5 59 7 2 +16401: 67 4 7 9 7 9 6 9 175 1 25 +211540826: 675 8 8 6 865 48 24 +999815: 921 8 778 43 82 4 6 80 +20460339: 890 237 97 59 70 +86357: 952 6 3 1 66 9 +2306987: 99 7 51 55 8 22 +1432751: 17 30 28 22 47 37 +5272: 236 45 16 76 7 1 25 2 +26384486: 39 224 84 475 14 +24715754: 80 557 97 1 3 8 5 9 1 24 +4536: 4 785 4 360 319 713 +55339200: 5 7 36 12 5 21 1 183 5 1 +73732059198: 4 9 11 906 7 7 14 3 699 +11785692665: 5 7 79 11 2 336 73 977 +92506: 4 7 20 84 5 6 9 91 +5228: 52 2 8 +5240069348: 8 131 500 3 66 345 3 +7656204532: 7 77 235 24 204 532 +507690334: 23 823 6 903 34 +152484: 9 3 6 343 2 713 3 1 6 +21576094: 586 193 490 1 82 17 +5036130: 333 1 333 682 343 45 +772: 4 45 3 4 40 +18599805: 3 4 49 1 1 6 37 4 142 75 +2344: 30 246 21 289 4 +54678825468: 9 7 9 1 1 3 1 82 9 7 4 324 +2332355134: 134 170 4 20 7 959 4 +4031694373: 6 3 30 7 478 78 2 9 373 +216365: 7 49 8 7 44 4 2 47 2 42 1 +828881432: 225 5 759 493 17 5 32 +2829: 3 13 177 +77069560740: 7 64 6 686 9 60 7 40 +102664: 347 5 5 59 2 +87813: 8 78 13 +279108: 6 9 49 40 487 571 92 +71831: 1 5 8 15 1 85 2 2 79 3 4 6 +12536652: 8 7 4 9 4 37 7 9 857 6 +18334976: 3 1 744 383 64 +319056: 1 280 9 23 8 6 +50997665: 893 4 2 163 2 16 174 5 +23910075: 849 8 542 305 1 313 5 +564033510: 2 4 978 573 201 501 6 +78185: 77 44 65 4 91 +2408327: 78 325 95 27 50 +6847167235786: 175 59 9 64 1 677 84 1 +676192027: 38 5 2 5 95 704 1 20 7 +9210625: 97 2 5 1 8 8 369 3 6 71 5 +149467508: 5 5 44 29 9 4 2 3 39 5 2 7 +2881560: 4 548 97 74 60 +705581: 4 8 9 5 47 5 457 19 11 +7099352: 307 47 123 71 4 +105596: 8 4 2 48 5 6 615 3 8 63 +1916395393: 3 8 93 53 450 4 21 9 3 1 +3046752: 728 5 837 8 64 +839964507: 8 82 22 8 1 4 2 3 3 55 2 +62763803899: 73 359 8 53 82 29 50 +26038272: 39 329 2 962 978 +34544966004: 48 58 645 79 6 9 +1091857: 9 131 89 9 7 86 +8739163: 174 78 5 1 63 +1931023586: 8 2 681 3 8 556 42 2 +50110335881: 50 3 492 2 679 55 26 +18450800: 2 3 558 4 23 46 44 4 4 +170480169: 213 5 1 5 8 50 6 6 4 121 +1583191718: 22 29 124 20 951 718 +58278300: 5 30 77 901 8 3 1 537 3 +19954019936: 46 597 974 28 746 +47835: 7 5 339 1 4 375 +2950614: 3 1 8 4 24 5 8 3 4 657 3 9 +20218418039376: 8 733 560 99 9 9 29 16 +593645: 9 9 842 5 94 9 3 86 4 1 5 +9756318: 9 75 6 3 10 8 +81682: 1 816 84 +16349319245: 510 1 7 61 8 441 811 4 +563: 2 38 298 222 3 +202257905: 1 7 3 3 748 9 8 5 5 8 5 5 +611: 2 36 7 8 2 24 7 66 +3052838376: 86 39 8 76 714 423 +24102208: 80 3 40 300 208 +101249729: 775 82 4 29 1 45 +251037: 597 7 60 297 1 +5135827: 73 3 4 8 3 7 7 642 752 +765688962: 10 755 6 889 62 +46054478: 3 11 392 32 78 +3046741074: 5 15 6 9 7 31 4 1 6 1 79 6 +78426872: 303 123 23 3 92 2 +105615620898: 808 840 247 5 8 14 63 +7246: 9 724 48 5 7 2 9 71 20 +411185: 45 30 57 51 282 29 +49916614734: 6 26 799 19 7 2 9 7 233 +20991601: 490 595 72 4 +162000: 9 5 6 66 45 24 +2376465: 6 74 5 7 586 7 7 5 91 +12886208: 3 728 2 6 4 83 976 72 8 +2260: 2 481 6 14 9 53 4 +2619488: 68 9 886 2 8 872 +55508933: 1 76 658 6 5 1 37 1 15 1 +622441037: 8 40 741 921 76 38 2 +746784739: 9 7 5 7 857 85 38 201 +42583: 42 240 58 276 9 +2095256607: 301 348 6 16 867 20 7 +30464656500: 952 32 656 236 264 +5482964: 1 781 5 17 8 7 4 +25593445: 30 5 69 9 7 2 4 4 47 6 2 4 +89866350: 255 80 659 91 607 7 +1056968220: 7 10 3 3 1 9 9 8 3 13 70 6 +2310: 62 8 33 +1235556740811: 1 68 6 6 5 80 8 738 49 5 +101463: 7 1 93 463 +1103257: 6 70 583 7 88 +8416: 24 310 663 48 265 +13214: 55 9 6 675 4 +694039781: 2 61 8 9 163 83 9 8 3 81 +16108: 2 3 1 2 82 1 6 4 5 9 6 344 +258732964: 3 3 36 77 2 3 1 1 4 4 4 +18318720000: 8 940 1 7 5 800 87 +73183536: 6 9 812 21 905 7 958 4 +3324894013: 52 160 664 67 96 541 +95257: 81 7 6 28 1 +57837: 33 581 97 9 3 +662694: 4 354 6 78 2 4 +2364889710: 399 1 6 8 2 343 4 9 4 6 5 +8610262887: 8 608 2 262 887 +3529: 34 20 6 94 9 +23103: 39 52 22 517 9 +425555: 33 5 17 3 23 54 +269307: 49 687 8 2 1 +9831334502: 60 687 25 9 90 2 +10570: 5 8 7 816 12 +23328: 43 2 54 +1405963584: 3 784 34 5 64 279 +512336794: 9 635 5 7 781 7 9 4 +44419: 91 703 55 189 560 +24226: 2 33 973 6 8 4 2 1 +53087944496: 88 3 542 5 23 96 371 6 +14463656829960: 6 762 76 61 754 465 +1543514: 92 4 2 926 6 4 17 5 623 +108444: 500 83 93 3 2 +5081: 4 89 5 2 7 5 5 2 6 806 3 +41042792: 5 4 472 9 69 53 963 7 +59919316: 49 10 919 310 6 +78366193: 9 76 179 8 77 80 993 +43544528825: 8 779 496 68 88 25 +209352887: 89 961 95 71 7 349 2 +17102646: 14 5 300 3 2 645 +1759905302: 166 4 872 4 8 371 22 +25339311: 620 83 328 406 445 +13384271114: 5 5 8 13 2 4 5 41 7 53 13 +2267301: 1 63 5 1 14 4 9 8 3 5 32 5 +157516: 2 6 71 46 3 67 13 743 +42511987: 604 2 31 7 940 49 +8559129600: 44 304 50 4 427 72 4 +3554208: 92 37 8 6 14 41 +11856636: 52 95 6 6 3 3 58 35 4 +7040454: 8 368 87 8 198 2 16 9 6 +67075662080: 4 88 9 96 6 5 256 973 +15365: 9 210 5 7 +3522050: 77 625 57 145 9 32 +143451167: 13 43 736 69 1 67 +6000: 1 2 73 5 3 5 6 643 9 7 7 5 +2634: 1 4 75 4 8 136 66 +19507917513: 9 7 50 3 6 71 4 5 35 4 5 7 +6195: 1 861 7 17 143 +25405216: 3 93 8 27 3 5 6 2 1 6 9 16 +658362315382: 2 351 635 9 62 7 7 2 +24025: 66 630 79 31 1 +5988: 527 7 593 38 6 74 +1161183: 5 4 66 2 7 29 9 95 7 86 +2143980333: 31 9 4 8 3 7 79 3 3 29 4 +271600187810: 3 2 8 500 8 2 682 1 2 5 7 +179937160: 7 465 4 586 65 +883238: 5 83 3 144 94 +236603: 234 1 164 790 648 +45930082: 416 8 3 24 56 46 +361: 44 78 218 14 7 +7561056: 5 193 6 328 113 1 +40701528: 21 36 997 6 9 +29834957064: 6 50 218 2 9 8 88 7 9 3 4 +162471582: 84 69 2 514 66 5 9 78 +182397: 9 2 23 86 9 +90664089: 3 488 983 63 33 +254720133: 3 24 446 4 879 +123643412: 2 14 1 3 60 637 85 6 9 3 +4229339058: 51 831 625 223 441 +61828439176: 5 76 640 3 5 4 1 7 599 5 +11346604843: 3 7 2 223 1 3 4 8 3 6 8 45 +5410078: 4 78 22 658 2 +2244856: 22 447 65 1 91 +194054: 437 7 9 38 62 91 7 +7160807: 8 51 24 196 69 86 17 +3121986: 37 98 861 +1990763: 71 57 486 4 3 5 6 45 53 +447665088: 3 8 776 43 559 +165253: 3 18 60 84 253 +181939844395: 963 664 43 1 472 4 9 +876727800: 7 5 8 5 524 1 45 3 90 52 +1210995: 52 4 4 2 66 849 7 1 6 3 6 +189588141: 4 337 6 190 6 94 3 7 14 +24355: 67 428 1 46 956 620 9 +14661: 3 98 1 2 2 6 2 90 453 2 4 +733201324719: 1 676 502 7 9 9 46 67 1 +76566: 5 17 6 39 4 14 7 +1840710690: 827 5 19 88 29 78 315 +118727441423: 8 9 3 12 4 849 768 37 5 +361804580: 719 2 2 125 29 86 1 +3391065514: 1 200 26 1 7 884 651 4 +39168: 934 42 3 2 4 +1015196283: 194 821 18 6 1 10 283 +1202295: 1 4 711 2 6 7 3 3 6 409 8 +2620: 88 764 9 92 726 941 +2915490003: 247 11 34 24 733 447 +121934120: 6 796 322 91 8 59 +857710: 420 1 5 8 5 3 7 8 842 7 +215: 4 3 3 48 157 +378639: 418 1 158 25 7 6 3 1 5 4 +731698: 95 876 48 359 2 56 +2012249: 515 3 7 1 4 36 9 3 3 776 +1207856: 8 298 9 1 4 8 7 706 4 2 +360: 5 8 9 +337610: 7 80 918 9 2 599 1 35 +7436787992: 4 50 205 8 4 876 207 8 +412920: 6 783 6 6 87 60 +13925: 6 7 3 6 1 419 3 5 +13777486: 7 8 6 7 31 2 2 4 3 64 398 +4427820206: 779 668 60 51 206 +1177848: 798 8 783 7 738 +40484341: 2 742 682 2 4 5 5 6 790 +1921228890: 48 236 8 212 90 +23256164: 238 2 51 19 5 4 4 20 4 +16124: 3 34 5 4 707 96 3 4 51 4 +7380844: 6 4 2 540 562 2 3 836 6 +15190: 78 1 67 9 98 +738150: 1 82 2 6 4 8 87 7 52 5 95 +2716245: 7 978 645 9 35 +557670792: 28 537 21 245 91 47 +487: 296 72 90 9 20 +11412362: 9 470 5 7 340 262 +292852: 6 360 8 44 8 +1591130113: 2 3 5 9 6 8 66 88 416 4 1 +123867174: 3 8 8 96 7 4 6 8 5 1 4 290 +1487: 85 88 655 606 53 +4335142: 67 15 173 34 2 9 5 +1650: 3 9 55 5 85 75 +467739: 2 9 67 387 1 2 653 361 +972474: 2 1 1 5 7 3 1 17 51 7 3 +13997123: 62 125 86 3 75 6 7 56 +1073: 953 68 52 +392496: 7 27 531 39 8 +1552320: 88 7 63 8 5 +150359: 8 3 99 138 2 71 4 +27306116366256: 972 440 9 37 38 312 +3087758: 43 6 7 9 761 +1359414: 9 19 1 9 314 79 7 93 6 7 +3511: 1 2 5 5 4 6 408 7 1 49 2 1 +1519753975: 5 969 9 2 4 4 1 9 3 4 652 +4962043800: 17 72 6 98 4 567 235 +713: 3 8 6 2 5 8 9 16 631 23 2 +330806768: 59 3 8 8 62 4 7 8 7 7 1 68 +3129984840: 6 8 882 2 6 44 6 3 4 9 5 8 +9598397: 8 9 942 839 5 +59508203: 5 85 56 2 3 3 5 5 3 25 2 +732275: 63 6 385 8 66 847 4 5 +1102: 98 177 2 1 2 +2348312: 15 5 9 62 5 9 1 69 7 8 8 +396951061159: 441 9 5 10 56 5 1 57 +6953694: 6 952 8 2 86 1 4 1 +692000: 6 19 682 7 2 925 10 5 8 +2532487: 20 5 324 7 4 13 +729354390: 6 50 838 6 74 2 7 5 8 3 6 +4302: 4 80 2 50 2 +295129889: 316 2 768 35 608 +12765102409: 797 81 8 893 7 4 4 6 +20661: 50 1 2 8 1 8 7 2 6 3 200 4 +139749288: 83 2 3 334 36 7 5 4 3 24 +10705351395: 3 929 8 519 2 192 99 +51524659: 159 6 54 34 5 823 5 33 +248123: 82 49 15 2 653 +596338: 1 4 4 910 625 6 1 7 78 +313140: 52 190 6 +5366: 6 7 33 116 30 +24097: 907 85 3 1 3 11 1 8 129 +8246068: 82 45 4 85 583 +17503168: 587 877 1 34 2 +84655465: 3 328 7 50 89 281 +11112385: 24 7 24 33 427 2 5 +200828160: 468 960 149 3 +969669: 15 1 8 6 226 9 79 34 23 +7322887248072: 61 8 5 9 620 4 6 9 6 5 72 +21805788: 8 756 9 4 5 6 5 73 9 7 9 6 +3368004965: 11 22 668 3 965 +191964102: 1 75 1 2 56 425 3 9 4 1 8 +229452893: 539 43 99 5 93 +1750029: 635 7 5 3 393 +5224824: 924 3 6 56 23 +129416: 191 9 36 36 65 +2385184: 32 83 898 1 90 6 +290964124306: 299 222 67 748 13 +1236001: 454 18 5 37 70 519 52 +15177419: 43 7 63 7 4 7 200 9 9 1 +11411: 8 30 46 1 151 214 5 1 +1790059: 447 4 1 4 59 +24755916: 44 2 4 1 4 4 3 944 543 +12739803835: 348 5 93 10 653 695 +658319: 52 483 5 3 3 1 82 8 6 6 3 +1054275964: 971 18 3 60 7 658 9 70 +46408869891: 65 5 996 9 59 6 5 99 9 +206861450: 881 1 4 60 393 557 5 +2330889: 8 1 80 215 1 10 1 83 3 +743694786: 3 841 8 583 9 9 26 56 2 +274066801: 3 6 7 78 469 5 237 8 7 7 +5297771: 298 1 8 7 8 77 2 9 8 2 27 +439440: 2 1 15 3 300 2 9 5 907 8 +48: 2 6 30 6 +297254952: 5 7 36 1 940 6 732 +314960685: 729 6 434 72 564 873 +153151149060: 782 59 19 67 2 79 35 6 +11811000: 19 6 767 87 423 600 +7616092: 8 264 875 32 92 +73684588: 1 72 68 3 349 331 908 +43753200: 44 2 714 606 95 +445628: 301 5 74 445 5 331 28 +109997568: 6 4 9 584 327 +506355: 98 490 861 87 +5285667: 5 185 469 75 1 1 3 6 8 3 +4124: 787 777 2 990 6 +2296: 6 3 52 53 3 19 6 9 699 +818730: 3 3 6 66 827 +2441: 7 95 9 38 53 4 6 2 813 +4517856: 4 35 51 6 63 747 +4342: 8 3 7 25 8 2 27 6 9 24 5 7 +128806662808: 19 5 5 23 9 696 8 131 +303754266816: 664 14 9 22 546 272 +31091671: 6 5 2 825 9 157 4 19 +4239694: 6 9 3 28 2 20 8 5 3 2 409 +120134644: 51 7 558 5 4 937 28 +1055661: 9 2 2 58 61 +47501: 89 840 1 9 644 30 11 1 diff --git a/y2024/src/bin/d7.rs b/y2024/src/bin/d7.rs new file mode 100644 index 0000000..078acb9 --- /dev/null +++ b/y2024/src/bin/d7.rs @@ -0,0 +1,20 @@ +use std::fs; + +use y2024::days::d7; + +fn main() { + part1(); + part2(); +} + +fn part1() { + let root = env!("CARGO_MANIFEST_DIR"); + let content = fs::read_to_string(format!("{root}/resources/7_input.txt")).unwrap(); + println!("{}", d7::process_part1(&content)); +} + +fn part2() { + let root = env!("CARGO_MANIFEST_DIR"); + let content = fs::read_to_string(format!("{root}/resources/7_input.txt")).unwrap(); + println!("{}", d7::process_part2(&content)); +} diff --git a/y2024/src/days/d7.rs b/y2024/src/days/d7.rs new file mode 100644 index 0000000..b07055c --- /dev/null +++ b/y2024/src/days/d7.rs @@ -0,0 +1,124 @@ +use std::iter::zip; + +pub fn process_part1(input: &str) -> i64 { + input + .lines() + .map(|line| { + let (eq_result, equation) = line.split_once(": ").unwrap(); + let eq_result = eq_result.parse::().unwrap(); + let numbers = equation + .split(" ") + .map(|num| num.parse::().unwrap()) + .collect::>(); + let mut operators = vec!["+"; numbers.len() - 1]; + let num_combinations = 2_u32.pow(operators.len() as u32); + for _ in 0..num_combinations { + let mut res = numbers[0]; + for (num, op) in zip(numbers[1..].iter(), operators.iter()) { + if op == &"+" { + res += num; + } + if op == &"*" { + res *= num; + } + } + if res == eq_result { + return res; + } + operators = binary_add_operators(operators); + } + 0 + }) + .sum() +} + +// permutating all combinations of + and * is like counting in binary +fn binary_add_operators(operators: Vec<&str>) -> Vec<&str> { + let mut new_operators = operators.clone(); + for (idx, operator) in operators.into_iter().enumerate() { + if operator == "+" { + new_operators[idx] = "*"; + break; + } + new_operators[idx] = "+"; + } + new_operators +} + +pub fn process_part2(input: &str) -> i64 { + input + .lines() + .map(|line| { + let (eq_result, equation) = line.split_once(": ").unwrap(); + let eq_result = eq_result.parse::().unwrap(); + let numbers = equation + .split(" ") + .map(|num| num.parse::().unwrap()) + .collect::>(); + let mut operators = vec!["+"; numbers.len() - 1]; + let num_combinations = 3_u32.pow(operators.len() as u32); + for _ in 0..num_combinations { + let mut res = numbers[0]; + for (num, op) in zip(numbers[1..].iter(), operators.iter()) { + if op == &"+" { + res += num; + } + if op == &"*" { + res *= num; + } + if op == &"||" { + res = format!("{res}{num}").parse().unwrap(); + } + } + if res == eq_result { + return res; + } + operators = ternary_add_operators(operators); + } + 0 + }) + .sum() +} + +// permutating all combinations of + and * is like counting in ternary +fn ternary_add_operators(operators: Vec<&str>) -> Vec<&str> { + let mut new_operators = operators.clone(); + for (idx, operator) in operators.into_iter().enumerate() { + if operator == "+" { + new_operators[idx] = "*"; + break; + } else if operator == "*" { + new_operators[idx] = "||"; + break; + } + new_operators[idx] = "+"; + } + new_operators +} + +#[cfg(test)] +mod tests { + use super::*; + + const INPUT: &str = "190: 10 19 +3267: 81 40 27 +83: 17 5 +156: 15 6 +7290: 6 8 6 15 +161011: 16 10 13 +192: 17 8 14 +21037: 9 7 18 13 +292: 11 6 16 20"; + + #[test] + fn part1() { + let result = process_part1(INPUT); + assert_eq!(result, 3749); + } + + #[test] + fn part2() { + let result = process_part2(INPUT); + assert_eq!(result, 11387); + } +} diff --git a/y2024/src/days/mod.rs b/y2024/src/days/mod.rs index 6401cf3..823daf8 100644 --- a/y2024/src/days/mod.rs +++ b/y2024/src/days/mod.rs @@ -9,3 +9,5 @@ pub mod d4; pub mod d5; pub mod d6; + +pub mod d7;