diff --git a/puzzle-input/09.txt b/puzzle-input/09.txt index e69de29..debc390 100644 --- a/puzzle-input/09.txt +++ b/puzzle-input/09.txt @@ -0,0 +1,200 @@ +-7 -13 -20 -17 16 108 297 630 1163 1961 3098 4657 6730 9418 12831 17088 22317 28655 36248 45251 55828 +-9 -7 2 18 41 71 108 152 203 261 326 398 477 563 656 756 863 977 1098 1226 1361 +18 43 75 124 227 464 984 2058 4198 8412 16712 33078 65251 128055 249539 482232 923410 1750729 3283185 6082488 11117019 +-6 -9 1 33 90 172 288 493 991 2381 6180 15868 38931 90838 202739 436138 910176 1850835 3676819 7144659 13586416 +4 9 25 77 200 439 849 1495 2452 3805 5649 8089 11240 15227 20185 26259 33604 42385 52777 64965 79144 +5 2 9 51 162 393 844 1732 3506 7019 13766 26196 48105 85116 145251 239599 383083 595328 901631 1334033 1932492 +11 18 41 84 156 288 558 1119 2219 4203 7513 12793 21443 37497 72774 159261 376223 905448 2137513 4866614 10633482 +-7 2 18 36 65 142 346 812 1745 3434 6266 10740 17481 27254 40978 59740 84809 117650 159938 213572 280689 +11 19 50 129 289 572 1037 1784 3023 5251 9662 19026 39467 83920 178728 376264 779550 1591540 3215954 6465863 12994746 +1 -2 -5 -14 -37 -70 -66 117 806 2700 7311 18018 42476 97800 221076 489549 1057575 2221442 4528883 8958026 17201249 +3 4 2 0 13 77 258 661 1439 2802 5026 8462 13545 20803 30866 44475 62491 85904 115842 153580 200549 +2 22 71 178 397 813 1554 2819 4934 8451 14319 24209 41225 71592 128702 242576 481304 998246 2133373 4625894 10050395 +26 48 82 133 204 293 390 474 510 446 210 -293 -1184 -2613 -4762 -7848 -12126 -17892 -25486 -35295 -47756 +-5 -12 -29 -59 -93 -100 -17 261 892 2116 4368 8656 17625 38189 87439 204929 476677 1079648 2360557 4970091 10083763 +-10 -1 33 102 228 464 926 1842 3619 6926 12788 22683 38631 63261 99839 152237 224820 322225 449003 609092 805086 +8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 +13 35 70 118 179 253 340 440 553 679 818 970 1135 1313 1504 1708 1925 2155 2398 2654 2923 +8 17 27 40 78 193 480 1102 2341 4697 9076 17153 32089 59951 112467 212187 401766 759993 1428425 2654118 4856056 +24 38 54 72 92 114 138 164 192 222 254 288 324 362 402 444 488 534 582 632 684 +8 4 11 41 100 180 255 299 351 670 2078 6723 19769 53022 132344 312037 701378 1511376 3133869 6270597 12137242 +-5 -3 15 73 209 483 993 1898 3447 6013 10131 16539 26221 40451 60837 89364 128435 180909 250135 339981 454857 +10 22 37 55 77 118 243 645 1797 4741 11637 26805 58689 123510 251940 501051 975272 1862428 3494593 6449123 11713769 +0 -4 -10 -18 -28 -40 -54 -70 -88 -108 -130 -154 -180 -208 -238 -270 -304 -340 -378 -418 -460 +11 18 44 105 226 462 942 1951 4082 8514 17495 35132 68639 130343 241152 437130 782773 1398278 2514658 4581595 8470712 +5 14 28 37 22 -45 -188 -378 -411 339 3356 11671 30847 70260 144640 275927 496066 853269 1429357 2387678 4096357 +8 23 51 99 175 288 448 666 954 1325 1793 2373 3081 3934 4950 6148 7548 9171 11039 13175 15603 +7 17 30 59 139 349 855 2002 4498 9748 20411 41268 80504 151522 275422 484293 825481 1367011 2204356 3468761 5337345 +5 16 28 36 46 83 190 414 775 1214 1516 1204 -600 -5351 -15298 -33746 -65367 -116564 -195892 -314540 -486878 +1 14 51 130 277 538 1012 1919 3720 7311 14320 27545 51582 93705 165075 282372 469963 762740 1209785 1879044 2863219 +9 10 21 44 86 176 391 891 1963 4074 7933 14562 25376 42272 67727 104905 157773 231226 331221 464920 640842 +23 45 77 130 229 426 830 1666 3390 6911 14007 28078 55483 107947 207116 393746 747109 1426493 2758601 5415954 10767573 +14 30 55 100 193 393 823 1726 3553 7106 13783 26017 48095 87734 159159 289129 528727 976483 1823973 3446196 6580946 +24 38 53 80 150 320 690 1451 2992 6104 12331 24532 47734 90374 166048 295907 511864 860802 1410001 2254032 3523398 +19 36 75 160 338 697 1399 2747 5313 10162 19215 35802 65464 117071 204331 347773 577295 935376 1481059 2294820 3484446 +24 40 64 99 147 221 382 807 1885 4324 9237 18175 33126 56665 92821 149967 248334 436856 827294 1658363 3409381 +4 8 9 3 -14 -46 -97 -171 -272 -404 -571 -777 -1026 -1322 -1669 -2071 -2532 -3056 -3647 -4309 -5046 +23 39 53 63 85 175 466 1226 2950 6517 13474 26555 50606 94169 172081 309570 548481 956443 1639995 2762927 4571363 +9 16 19 19 31 98 320 902 2222 4921 10024 19116 34622 60277 101923 168837 275879 446854 719609 1153537 1840337 +22 34 49 81 149 278 509 933 1777 3587 7585 16352 35161 74650 156265 323370 663829 1355668 2759074 5601431 11349190 +18 27 40 57 75 102 195 539 1587 4278 10335 22611 45407 84684 148270 246829 398132 641241 1075770 1958253 3919271 +7 23 53 112 225 442 870 1739 3539 7298 15125 31225 63713 127719 250494 479506 894863 1627825 2887677 4999838 8458785 +29 45 62 80 99 119 140 162 185 209 234 260 287 315 344 374 405 437 470 504 539 +15 44 89 156 258 427 735 1324 2445 4506 8129 14216 24024 39249 62119 95496 142987 209064 299193 419972 579278 +11 28 45 58 69 108 269 760 1967 4532 9445 18150 32665 55716 90885 142772 217171 321260 463805 655378 908589 +17 17 15 24 66 181 449 1025 2189 4431 8652 16719 32956 67825 146254 325080 727257 1605293 3453397 7197730 14507790 +12 9 14 40 115 304 742 1678 3530 6951 12906 22760 38377 62230 97522 148318 219688 317861 450390 626328 856415 +5 3 11 46 132 313 687 1467 3072 6243 12164 22552 39693 66534 107430 171543 284380 520864 1089886 2532667 6156915 +10 9 23 79 219 500 994 1788 2984 4699 7065 10229 14353 19614 26204 34330 44214 56093 70219 86859 106295 +6 14 31 68 153 341 721 1420 2604 4476 7271 11248 16679 23835 32969 44296 57970 74058 92511 113132 135541 +3 11 41 103 211 397 745 1466 3052 6576 14264 30579 64248 131945 264742 519084 995408 1870972 3462282 6353774 11677012 +17 43 83 137 205 287 383 493 617 755 907 1073 1253 1447 1655 1877 2113 2363 2627 2905 3197 +4 22 63 136 251 434 763 1431 2837 5700 11184 21014 37554 63808 103294 159729 236450 335482 456149 593108 733669 +21 38 62 98 151 226 328 462 633 846 1106 1418 1787 2218 2716 3286 3933 4662 5478 6386 7391 +15 32 60 111 210 416 853 1749 3494 6760 12783 23992 45279 86333 165636 317061 600849 1122780 2069918 3780673 6884720 +14 19 23 23 26 55 156 412 970 2087 4201 8033 14726 26027 44518 73902 119350 187915 289019 435019 641858 +6 20 43 76 129 234 464 977 2115 4600 9891 20813 42662 85156 165874 316242 591732 1088788 1972139 3517666 6177927 +8 16 24 32 40 48 56 64 72 80 88 96 104 112 120 128 136 144 152 160 168 +10 3 1 7 19 27 18 -5 21 327 1591 5625 16923 45854 114786 269240 597632 1265983 2579549 5094119 9819887 +-9 -8 -2 9 25 46 72 103 139 180 226 277 333 394 460 531 607 688 774 865 961 +19 42 89 170 301 520 912 1643 3003 5458 9711 16772 28037 45376 71230 108717 161747 235146 334789 467742 642413 +16 33 74 154 306 593 1120 2046 3596 6073 9870 15482 23518 34713 49940 70222 96744 130865 174130 228282 295274 +22 35 62 111 190 307 470 687 966 1315 1742 2255 2862 3571 4390 5327 6390 7587 8926 10415 12062 +8 15 28 68 181 444 978 1975 3747 6812 12042 20919 36013 61989 107908 192559 356508 688355 1379990 2839368 5914487 +27 46 68 94 125 160 194 216 207 138 -32 -358 -911 -1780 -3074 -4924 -7485 -10938 -15492 -21386 -28891 +0 -8 -16 -7 49 191 455 848 1315 1734 2017 2453 4502 12337 35534 93428 221786 482596 977934 1869049 3401999 +18 24 27 23 4 -31 -43 119 868 3197 9362 24339 58862 135556 300870 647427 1354350 2757486 5467717 10564303 19902144 +21 45 89 158 254 383 574 912 1587 2961 5655 10658 19460 34211 57908 94612 149697 230133 344805 504870 724154 +14 15 14 22 61 177 464 1099 2388 4823 9150 16448 28219 46489 73920 113933 170842 249999 357950 502602 693401 +3 -2 -5 15 89 265 633 1380 2889 5899 11755 22805 43053 79281 143115 255250 455091 824330 1545635 3046273 6338037 +18 26 47 111 266 581 1149 2090 3554 5724 8819 13097 18858 26447 36257 48732 64370 83726 107415 136115 170570 +29 45 77 151 299 567 1036 1856 3293 5789 10035 17057 28315 45815 72234 111058 166733 244829 352217 497259 690011 +5 25 52 79 109 179 391 940 2124 4316 7873 12952 19198 25264 28118 22087 -2417 -60549 -175126 -379235 -719429 +12 32 63 115 218 440 913 1869 3702 7102 13361 25046 47402 91152 177935 350754 694078 1372757 2707583 5321228 10415908 +7 -1 -7 -11 -18 -38 -86 -182 -351 -623 -1033 -1621 -2432 -3516 -4928 -6728 -8981 -11757 -15131 -19183 -23998 +9 23 45 79 129 199 293 415 569 759 989 1263 1585 1959 2389 2879 3433 4055 4749 5519 6369 +22 39 66 108 167 241 329 448 664 1136 2183 4426 9151 19211 41068 89024 193433 416080 878871 1818607 3695330 +23 44 75 123 211 397 804 1661 3355 6494 11981 21099 35607 57847 90862 138525 205679 298288 423599 590315 808779 +16 38 64 98 161 299 591 1157 2166 3844 6482 10444 16175 24209 35177 49815 68972 93618 124852 163910 212173 +10 19 29 37 41 40 34 24 12 1 -5 -1 19 62 136 250 414 639 937 1321 1805 +6 23 52 90 146 253 495 1068 2407 5443 12115 26362 55969 115849 233620 458692 876524 1630255 2952566 5211402 8974084 +12 14 25 50 105 229 500 1067 2219 4521 9050 17756 33958 62993 113155 197490 338142 577468 1005207 1820402 3463239 +10 31 67 115 169 225 288 375 504 655 685 175 -1817 -7127 -19014 -42885 -87258 -165009 -294953 -503813 -828635 +2 0 7 31 80 162 285 457 686 980 1347 1795 2332 2966 3705 4557 5530 6632 7871 9255 10792 +26 42 64 104 197 421 917 1904 3684 6632 11166 17692 26519 37739 51067 65636 79742 90534 93644 82752 49081 +0 -2 2 30 122 343 792 1626 3105 5659 9974 17095 28553 46542 74211 116239 180153 279599 442457 729999 1279059 +6 8 4 1 21 117 411 1168 2931 6760 14642 30165 59563 113214 207577 367376 627640 1035204 1649960 2548457 3837989 +14 18 34 81 185 375 689 1205 2114 3863 7436 14950 30997 65709 141643 308797 676286 1476940 3194726 6808075 14240233 +19 27 34 55 127 315 715 1467 2814 5275 10041 19753 39880 80983 162228 316597 598341 1093323 1933012 3313011 5517133 +-2 11 34 73 150 306 596 1075 1775 2672 3639 4376 4301 2377 -3161 -15228 -38524 -80463 -152496 -271949 -464520 +2 5 11 21 34 40 6 -138 -499 -1185 -2199 -3210 -3119 704 13694 46135 116332 255393 514255 973771 1758892 +5 1 0 15 75 234 589 1315 2725 5363 10138 18507 32715 56100 93471 151567 239605 369925 558740 826999 1201371 +-4 -8 -19 -28 -6 112 456 1279 3068 6745 14035 28190 55529 108842 214888 430475 875784 1801146 3716889 7639288 15545792 +9 17 33 66 138 299 642 1318 2551 4653 8039 13242 20928 31911 47168 67854 95317 131113 177021 235058 307494 +17 35 60 89 134 250 580 1427 3376 7513 15839 32094 63463 124166 242989 478900 953054 1913829 3868162 7845060 15919489 +20 32 44 56 68 80 92 104 116 128 140 152 164 176 188 200 212 224 236 248 260 +8 16 33 77 181 415 919 1955 3994 7861 14967 27662 49747 87186 149061 248814 405820 647334 1010853 1546931 2322481 +11 28 69 147 285 535 1011 1938 3714 6977 12664 22044 36702 58446 89104 130173 182277 244386 312743 379441 430587 +5 16 40 83 168 362 816 1818 3859 7712 14524 25921 44126 72090 113636 173616 258081 374464 531776 740815 1014388 +16 35 75 148 277 516 989 1966 4013 8289 17120 35055 70698 139726 269720 507983 934958 1689391 3019337 5389670 9709035 +4 3 6 13 24 39 58 81 108 139 174 213 256 303 354 409 468 531 598 669 744 +14 23 53 115 221 386 632 997 1549 2406 3775 6064 10239 18905 39323 91199 225452 566777 1405141 3383325 7865301 +-2 0 8 28 69 152 326 689 1412 2764 5136 9062 15235 24516 37934 56675 82058 115496 158440 212304 278369 +-8 -7 5 47 156 400 913 1964 4069 8148 15728 29218 52375 91333 157167 272256 485278 904443 1766939 3576533 7363614 +7 15 21 25 27 27 25 21 15 7 -3 -15 -29 -45 -63 -83 -105 -129 -155 -183 -213 +-7 -3 7 27 64 130 244 432 726 1169 1841 2933 4922 8963 17755 37421 81459 178697 388583 829267 1727040 +10 20 38 75 152 300 560 983 1630 2572 3890 5675 8028 11060 14892 19655 25490 32548 40990 50987 62720 +10 23 53 125 292 650 1360 2688 5083 9331 16854 30279 54512 98783 180644 334105 626911 1198378 2343160 4695214 9623371 +20 28 36 44 52 60 68 76 84 92 100 108 116 124 132 140 148 156 164 172 180 +19 23 27 31 35 39 43 47 51 55 59 63 67 71 75 79 83 87 91 95 99 +10 16 18 25 57 146 348 787 1759 3939 8780 19315 41854 89662 190899 405427 859472 1815134 3805874 7893237 16139927 +21 33 45 57 69 81 93 105 117 129 141 153 165 177 189 201 213 225 237 249 261 +-4 5 21 35 41 39 33 32 83 399 1692 5881 17418 45561 108022 236530 484974 940929 1741519 3094735 5307503 +14 14 21 39 71 119 182 256 344 505 1024 2885 8891 26014 69889 172804 397098 856576 1749399 3406923 6364159 +17 26 50 115 260 544 1074 2064 3933 7448 13916 25427 45148 77666 129376 208908 327585 499902 744014 1082219 1541420 +5 9 5 -2 11 104 414 1230 3130 7240 15749 32965 67487 136597 274888 550617 1095478 2156506 4182468 7960663 14821890 +19 24 26 28 40 76 151 283 505 892 1608 2978 5590 10432 19069 33865 58255 97072 156934 246696 377972 +9 31 69 135 249 450 819 1514 2817 5193 9361 16377 27729 45444 72207 111492 167705 246339 354141 499291 691593 +13 26 46 85 178 392 835 1665 3099 5422 8996 14269 21784 32188 46241 64825 88953 119778 158602 206885 266254 +-6 -10 -14 -18 -22 -26 -30 -34 -38 -42 -46 -50 -54 -58 -62 -66 -70 -74 -78 -82 -86 +1 10 34 72 120 171 219 266 326 415 511 463 -177 -2430 -8310 -21429 -47833 -97120 -183896 -329630 -564974 +2 -2 -15 -44 -92 -138 -108 158 938 2654 5887 11376 19996 32710 50490 74202 104450 141374 184397 231916 280932 +11 35 74 135 242 446 835 1544 2765 4757 7856 12485 19164 28520 41297 58366 80735 109559 146150 191987 248726 +8 19 42 80 132 189 241 306 485 1043 2520 5907 13028 27542 57570 122086 265202 585743 1294586 2819798 5990472 +16 17 23 54 151 383 854 1710 3146 5413 8825 13766 20697 30163 42800 59342 80628 107609 141355 183062 234059 +10 20 33 53 100 220 497 1067 2135 3997 7070 11934 19391 30547 46924 70610 104456 152330 219439 312731 441390 +18 36 62 94 131 175 240 386 809 2033 5271 13060 30366 66588 139445 282934 563974 1117027 2214820 4409937 8813547 +12 20 20 7 -15 -8 134 627 1848 4396 9162 17403 30809 51544 82232 125847 185452 263716 362120 479743 611497 +11 13 22 53 137 325 693 1348 2435 4145 6724 10483 15809 23177 33163 46458 63883 86405 115154 151441 196777 +25 45 66 84 108 187 450 1170 2872 6511 13749 27360 51789 93885 163819 276186 451275 716473 1107748 1671132 2464098 +-6 -12 -15 2 68 225 530 1068 2002 3721 7226 15051 33290 75725 171628 379477 809386 1657086 3251051 6110584 11004408 +11 18 40 97 220 452 861 1571 2815 5025 9012 16373 30422 58227 114830 231587 472079 961761 1942498 3872496 7610088 +17 26 44 83 180 427 1022 2347 5080 10365 20112 37593 68655 124102 224120 406047 737339 1336268 2403724 4270495 7465582 +18 38 63 106 194 368 683 1208 2026 3234 4943 7278 10378 14396 19499 25868 33698 43198 54591 68114 84018 +22 34 53 83 134 229 408 728 1258 2068 3211 4697 6458 8303 9862 10518 9326 4918 -4607 -21809 -50050 +1 8 41 126 314 699 1443 2813 5244 9454 16644 28806 49119 82317 134740 213501 323787 462724 607435 693862 581560 +-6 -11 -6 30 132 368 870 1891 3911 7819 15197 28726 52723 93802 161631 269731 436232 684465 1043228 1546518 2232470 +4 21 50 90 144 233 413 800 1629 3400 7193 15259 32019 65665 130751 252654 475794 879227 1605688 2912932 5257986 +5 14 32 59 95 140 194 257 329 410 500 599 707 824 950 1085 1229 1382 1544 1715 1895 +13 33 66 126 231 398 649 1055 1866 3806 8663 20402 47243 105634 228138 479575 990488 2026260 4127769 8391895 17018656 +0 11 44 115 247 483 910 1705 3232 6247 12322 24716 50177 102712 211533 437792 909464 1892695 3934100 8136465 16676843 +-8 -4 18 79 219 509 1080 2181 4277 8197 15341 27954 49474 84960 141605 229338 361518 555722 834628 1226993 1768725 +11 26 44 67 103 166 276 459 747 1178 1796 2651 3799 5302 7228 9651 12651 16314 20732 26003 32231 +10 17 24 31 38 45 52 59 66 73 80 87 94 101 108 115 122 129 136 143 150 +12 20 38 69 125 247 539 1217 2676 5579 10982 20550 37021 65272 114668 203880 370166 686608 1294063 2462222 4711849 +4 9 25 63 137 274 535 1064 2200 4723 10374 22925 50339 109054 232324 486174 999493 2020318 4020832 7893516 15318474 +12 34 69 117 178 252 339 439 552 678 817 969 1134 1312 1503 1707 1924 2154 2397 2653 2922 +7 7 9 11 13 35 156 594 1857 5006 12100 26971 56659 114234 224577 436452 847747 1657609 3271827 6510091 13001441 +1 11 26 57 122 248 481 908 1713 3329 6815 14679 32471 71553 153463 316147 621925 1166235 2084772 3554369 5779564 +21 32 51 98 211 464 1008 2158 4559 9474 19247 38004 72665 134350 240272 416220 699745 1144172 1823571 2838830 4324983 +19 40 80 155 289 524 941 1698 3091 5644 10234 18257 31841 54112 89519 144224 226563 347584 521668 767239 1107569 +4 17 35 58 86 119 157 200 248 301 359 422 490 563 641 724 812 905 1003 1106 1214 +9 21 37 71 148 303 580 1031 1715 2697 4047 5839 8150 11059 14646 18991 24173 30269 37353 45495 54760 +3 -4 -19 -49 -105 -194 -301 -361 -221 408 2009 5327 11447 21882 38671 64487 102755 157780 234885 340559 482615 +-1 15 57 149 325 626 1107 1874 3186 5683 10851 21931 45652 95458 197355 400184 793097 1534351 2897325 5342001 9623135 +11 5 3 23 104 319 792 1719 3393 6233 10817 17919 28550 44003 65902 96255 137511 192621 265103 359111 479508 +2 11 39 97 210 437 907 1886 3907 8027 16336 32959 66001 131237 258906 505804 976072 1855739 3468317 6361677 11440196 +7 23 48 82 125 177 238 308 387 475 572 678 793 917 1050 1192 1343 1503 1672 1850 2037 +22 33 60 125 258 494 865 1383 2010 2611 2886 2277 -154 -5880 -17101 -36977 -69906 -121851 -200720 -316803 -483270 +7 15 28 52 99 190 369 727 1442 2859 5663 11238 22356 44402 87414 169301 320697 592015 1063382 1858264 3161729 +12 9 0 -6 15 118 416 1125 2649 5754 11939 24243 48992 99476 203375 417119 852646 1726039 3445110 6768040 13095417 +5 16 36 67 111 170 246 341 457 596 760 951 1171 1422 1706 2025 2381 2776 3212 3691 4215 +4 23 56 99 156 248 421 755 1374 2467 4376 7935 15547 34154 82661 209211 529188 1304971 3106480 7122287 15741466 +8 6 9 17 38 113 358 1040 2724 6570 14949 32737 70042 147922 310214 647496 1344382 2770339 5649660 11372933 22559314 +7 24 49 85 147 283 613 1408 3243 7267 15639 32182 63307 119256 215707 375775 632431 1031346 1634149 2522067 3799891 +16 24 50 123 292 629 1230 2225 3819 6403 10814 18911 34805 67391 135378 276977 568098 1155841 2319037 4575691 8869604 +15 30 43 62 106 218 498 1160 2613 5562 11121 20926 37232 62974 101768 157824 235739 340134 475095 643374 845302 +1 -7 -14 -6 41 167 450 1069 2460 5671 13117 30099 67729 148380 315619 652106 1311775 2577881 4968124 9425160 17660189 +-8 1 20 50 98 177 318 619 1372 3340 8313 20166 46784 103420 218323 441825 860520 1618715 2949994 5222522 9002638 +12 22 41 69 106 152 207 271 344 426 517 617 726 844 971 1107 1252 1406 1569 1741 1922 +8 20 48 107 222 437 830 1532 2764 4935 8886 16420 31326 61186 120348 234555 447840 832430 1502548 2633161 4484894 +9 10 16 42 130 371 936 2116 4371 8388 15148 26002 42756 67765 104036 155340 226333 322686 451224 620074 838822 +10 18 28 49 98 208 463 1087 2621 6225 14148 30437 62045 120728 226670 416047 757612 1389624 2601392 5009265 9924972 +2 20 47 79 112 142 165 177 174 152 107 35 -68 -206 -383 -603 -870 -1188 -1561 -1993 -2488 +8 22 55 108 178 253 304 276 81 -403 -1322 -2819 -4983 -7766 -10859 -13517 -14322 -10872 617 25810 72868 +9 27 53 94 165 289 498 854 1523 2950 6199 13539 29375 61642 123800 237589 436725 771741 1316201 2174540 3491809 +15 28 55 110 209 381 684 1225 2198 3983 7399 14286 28714 59287 123247 253467 510187 1001075 1917235 3602149 6691733 +21 44 91 172 299 507 901 1747 3628 7687 15986 32042 61703 114800 208676 376237 684665 1278676 2478899 5000726 10428669 +14 38 84 177 365 726 1378 2498 4352 7329 11960 18895 28820 42342 59981 82621 113134 160460 248272 431561 826139 +24 31 28 10 -16 -17 79 392 1092 2391 4522 7702 12076 17639 24133 30916 36800 39855 37176 24610 -3560 +4 22 55 103 166 244 337 445 568 706 859 1027 1210 1408 1621 1849 2092 2350 2623 2911 3214 +7 14 32 62 97 118 94 3 -84 224 2136 8640 26235 68010 159278 348356 727862 1477103 2945349 5811499 11381698 +-6 7 36 87 177 346 675 1319 2572 5000 9719 18965 37197 73063 142586 273832 513132 932979 1643116 2811861 4720519 +4 14 35 69 110 155 236 494 1326 3644 9297 21747 47226 96985 192180 374989 733736 1457890 2953815 6078997 12598990 +8 15 25 32 41 84 236 640 1570 3596 7975 17500 38254 83172 179283 382497 807737 1689731 3503891 7203269 14678446 +18 43 82 133 207 348 665 1387 2970 6314 13196 27115 54918 109897 217631 426934 830390 1603237 3078046 5889885 11259709 +7 16 34 70 138 257 451 749 1185 1798 2632 3736 5164 6975 9233 12007 15371 19404 24190 29818 36382 +6 16 48 127 295 614 1166 2050 3377 5265 7837 11226 15592 21157 28265 37475 49696 66374 89742 123145 171453 +-1 11 47 128 283 546 949 1501 2141 2659 2596 1172 -2619 -9391 -17360 -16936 22595 184007 670797 1953636 5071415 +8 30 63 105 151 198 267 456 1040 2636 6455 14680 31070 62067 119125 223969 420524 801150 1561871 3113443 6295205 +-8 0 28 99 264 627 1393 2946 5959 11533 21357 37876 64449 105474 166452 253957 375474 539062 752794 1023921 1357702 +9 14 26 44 78 176 465 1206 2863 6186 12308 22856 40076 66972 107459 166530 250437 366886 525246 736772 1014842 +0 13 39 78 130 195 273 364 468 585 715 858 1014 1183 1365 1560 1768 1989 2223 2470 2730 +27 51 94 181 355 676 1224 2120 3591 6133 10876 20339 39917 80764 165455 339410 694513 1418541 2898500 5934335 12173541 +-1 4 28 92 239 540 1101 2089 3810 6888 12614 23579 44823 86006 165678 319866 619500 1205979 2364211 4673277 9316806 +26 35 39 38 38 57 137 369 938 2207 4893 10457 21968 45992 96675 204449 434210 922191 1948235 4072372 8383690 +1 12 48 120 252 508 1042 2174 4490 8959 17055 30867 53175 87465 137851 208867 305087 430526 587770 776778 993294 +20 49 91 148 223 326 488 782 1360 2535 4967 10052 20663 42452 85992 170118 326916 608909 1099099 1924644 3275079 +8 21 38 68 129 258 528 1072 2114 4007 7278 12680 21251 34380 53880 82068 121852 176825 251366 350748 481253 +22 34 45 66 124 277 637 1405 2925 5765 10843 19666 34909 61964 112975 216635 440256 936212 2034033 4413874 9419018 +7 5 6 19 51 115 265 674 1768 4434 10360 22690 47477 97048 197614 405667 841505 1754475 3644414 7478901 15068411 diff --git a/src/lib.rs b/src/lib.rs index 4166646..847ec29 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,7 @@ pub fn run_all(data_dir: &str) { solutions::day06::main(data_dir); solutions::day07::main(data_dir); solutions::day08::main(data_dir); - // solutions::day09::main(data_dir); + solutions::day09::main(data_dir); // solutions::day10::main(data_dir); // solutions::day11::main(data_dir); // solutions::day12::main(data_dir); @@ -39,7 +39,7 @@ pub fn run_day(data_dir: &str, day: &usize) { 6 => solutions::day06::main(data_dir), 7 => solutions::day07::main(data_dir), 8 => solutions::day08::main(data_dir), - // 9 => solutions::day09::main(data_dir), + 9 => solutions::day09::main(data_dir), // 10 => solutions::day10::main(data_dir), // 11 => solutions::day11::main(data_dir), // 12 => solutions::day12::main(data_dir), diff --git a/src/solutions/day09.rs b/src/solutions/day09.rs new file mode 100644 index 0000000..e7905a3 --- /dev/null +++ b/src/solutions/day09.rs @@ -0,0 +1,70 @@ +use std::num::ParseIntError; + +use crate::data::load; +use thiserror::Error; + +#[derive(Error, Debug, PartialEq, Eq)] +pub enum PuzzleErr { + #[error("Integer parsing error.")] + Disconnect(#[from] ParseIntError), +} + +fn parse_input(data: &str) -> Result>, PuzzleErr> { + Ok(data + .trim() + .lines() + .map(|line| { + line.split_whitespace() + .map(|x| x.parse()) + .collect::, ParseIntError>>() + }) + .collect::, ParseIntError>>()?) +} + +fn oasis_prediction(seq: &[i32]) -> i32 { + let mut diffs = Vec::from_iter([seq.to_owned()]); + loop { + let next_seq = diffs + .last() + .unwrap() + .windows(2) + .map(|a| a[1] - a[0]) + .collect::>(); + diffs.push(next_seq.clone()); + if next_seq.iter().all(|a| a == &0) { + break; + } + } + + let mut preds = Vec::from_iter([0]); + for i in (1..diffs.len()).rev() { + preds.push(preds.last().unwrap() + diffs[i - 1].last().unwrap()); + } + *preds.last().unwrap() +} + +pub fn puzzle_1(input: &str) -> Result { + let seqs = parse_input(input)?; + Ok(seqs.iter().map(|s| oasis_prediction(s)).sum()) +} + +pub fn main(data_dir: &str) { + println!("Day 9: Mirage Maintenance"); + let data = load(data_dir, 9, None); + + // Puzzle 1. + let answer_1 = puzzle_1(&data); + match answer_1 { + Ok(x) => println!(" Puzzle 1: {}", x), + Err(e) => panic!("No solution to puzzle 1: {}.", e), + } + assert_eq!(answer_1, Ok(1666172641)); + + // Puzzle 2. + // let answer_2 = puzzle_2(&data); + // match answer_2 { + // Ok(x) => println!(" Puzzle 2: {}", x), + // Err(e) => panic!("No solution to puzzle 2: {}", e), + // } + // assert_eq!(answer_2, Ok(21003205388413)) +} diff --git a/src/solutions/mod.rs b/src/solutions/mod.rs index 50f9410..9dcdfa1 100644 --- a/src/solutions/mod.rs +++ b/src/solutions/mod.rs @@ -6,7 +6,7 @@ pub mod day05; pub mod day06; pub mod day07; pub mod day08; -// pub mod day09; +pub mod day09; // pub mod day10; // pub mod day11; // pub mod day12; diff --git a/tests/test_day09.rs b/tests/test_day09.rs new file mode 100644 index 0000000..bae4a58 --- /dev/null +++ b/tests/test_day09.rs @@ -0,0 +1,13 @@ +use aoc_2023::solutions::day09::puzzle_1; + +const EXAMPLE_INPUT_1: &str = " +0 3 6 9 12 15 +1 3 6 10 15 21 +10 13 16 21 30 45 +"; + +#[test] +fn example_1_puzzle_1() { + let _ = env_logger::try_init(); + assert_eq!(puzzle_1(self::EXAMPLE_INPUT_1), Ok(114)); +}