diff --git a/2023/09/go.mod b/2023/09/go.mod new file mode 100644 index 0000000..91682e2 --- /dev/null +++ b/2023/09/go.mod @@ -0,0 +1,3 @@ +module git.tristans.cloud/tristan/aoc/2023/09 + +go 1.21.4 diff --git a/2023/09/input.txt b/2023/09/input.txt new file mode 100644 index 0000000..dae3801 --- /dev/null +++ b/2023/09/input.txt @@ -0,0 +1,200 @@ +12 23 42 82 168 344 680 1276 2260 3777 5966 8922 12640 16938 21356 25028 26524 23659 13266 -9070 -49320 +15 34 71 134 240 423 740 1277 2160 3570 5754 9047 14050 22517 40542 87994 223135 601424 1607163 4133978 10159334 +15 39 81 147 248 422 771 1513 3049 6045 11529 21003 36570 61076 98267 152961 231235 340627 490353 691539 957468 +6 11 39 100 210 397 707 1227 2161 4026 8085 17220 37600 81773 174330 362339 734970 1461479 2866653 5582890 10857048 +10 21 40 70 110 160 247 497 1286 3512 9042 21403 46799 95536 183913 336607 589690 995214 1631382 2631681 4270936 +27 38 57 93 169 347 778 1790 4032 8709 17982 35689 68709 129621 241968 450775 843758 1594525 3051300 5919610 11636474 +0 -4 -8 -12 -16 -20 -24 -28 -32 -36 -40 -44 -48 -52 -56 -60 -64 -68 -72 -76 -80 +1 -2 -3 16 82 231 523 1096 2290 4870 10357 21425 42223 78313 135653 217669 318919 413118 432325 232846 -458168 +13 12 21 69 199 471 972 1841 3324 5890 10472 18967 35283 67555 132843 266976 544707 1119752 2301727 4699093 9476243 +13 33 65 109 165 233 313 405 509 625 753 893 1045 1209 1385 1573 1773 1985 2209 2445 2693 +1 -7 -8 18 99 273 589 1103 1865 2893 4130 5380 6219 5877 3087 -4103 -18559 -44335 -86996 -153994 -255101 +3 17 45 93 165 264 395 571 824 1221 1892 3125 5745 12419 31491 86912 241517 647397 1647963 3973625 9099649 +10 23 36 54 93 182 365 703 1276 2185 3554 5532 8295 12048 17027 23501 31774 42187 55120 70994 90273 +12 25 56 107 187 336 661 1384 2902 5859 11230 20417 35357 58642 93651 144694 217168 317725 454452 637063 877103 +26 52 92 163 304 579 1070 1857 2998 4558 6798 10729 19368 40209 89648 200383 433154 894600 1763496 3328199 6038784 +-2 4 21 57 124 243 467 947 2087 4859 11374 25825 55922 114901 224068 415613 735200 1244058 2022171 3180313 4904132 +2 8 22 52 121 282 649 1447 3091 6335 12598 24686 48299 94956 187324 368505 717934 1379022 2609637 4880779 9081913 +20 24 36 69 136 250 424 671 1004 1436 1980 2649 3456 4414 5536 6835 8324 10016 11924 14061 16440 +5 11 26 50 83 125 176 236 305 383 470 566 671 785 908 1040 1181 1331 1490 1658 1835 +12 22 23 24 48 144 418 1087 2572 5679 11974 24545 49482 98650 194806 381099 739121 1424384 2738677 5282639 10285311 +5 6 13 28 53 90 141 208 293 398 525 676 853 1058 1293 1560 1861 2198 2573 2988 3445 +10 16 41 102 234 506 1054 2152 4351 8726 17285 33631 64079 119717 220538 404035 742961 1380936 2601168 4954146 9486849 +15 15 18 32 74 184 464 1152 2736 6111 12795 25277 47725 87635 159744 295021 560437 1100595 2221932 4556766 9371860 +17 33 61 120 248 516 1061 2159 4365 8753 17295 33424 62832 114560 202443 346979 577697 936105 1479305 2284368 3453568 +22 49 90 156 268 457 764 1240 1946 2953 4342 6204 8640 11761 15688 20552 26494 33665 42226 52348 64212 +20 36 73 141 257 455 802 1430 2605 4884 9472 18990 39005 80867 166705 338022 670560 1300620 2472769 4626995 8555831 +23 50 96 173 301 507 816 1225 1662 1961 1934 1707 2654 9616 35844 113649 316753 805908 1919180 4344905 9442347 +26 37 39 32 27 65 248 783 2040 4632 9560 18577 35201 67391 134001 279031 600774 1307683 2819725 5943834 12165623 +21 37 61 107 198 368 672 1208 2155 3831 6775 11857 20420 34458 56834 91542 144017 221497 333441 492007 712594 +4 2 -3 -6 16 117 394 1006 2223 4545 8949 17340 33299 63236 118068 215550 383390 663276 1115933 1827310 2915970 +7 5 7 23 82 257 711 1785 4160 9138 19104 38254 73705 137144 247226 432998 738709 1230467 2005325 3203521 5024764 +2 18 49 96 159 249 410 749 1469 2897 5496 9847 16584 26262 39135 54818 71804 86804 93875 83298 40165 +15 26 33 31 22 23 72 239 657 1604 3708 8453 19418 45245 106508 250980 586179 1345990 3021895 6612319 14080774 +12 29 67 144 279 503 879 1531 2686 4737 8339 14554 25065 42483 70775 115845 186304 294469 457635 699668 1052971 +19 23 32 47 59 55 31 16 127 708 2665 8203 22309 55516 128736 281274 583539 1156461 2200214 4035543 7161807 +10 9 16 45 125 309 685 1389 2620 4657 7878 12781 20007 30365 44859 64717 91422 126745 172780 231981 307201 +8 17 41 85 154 258 419 674 1059 1548 1914 1491 -1120 -8181 -22171 -42982 -60172 -35063 136561 696871 2159272 +6 2 9 46 144 356 768 1524 2902 5509 10696 21316 42928 85429 164786 303955 531245 873760 1344656 1929684 2599487 +7 13 39 95 204 419 839 1630 3062 5586 10021 18045 33466 65340 135201 293071 651731 1458387 3242246 7115374 15381672 +13 16 13 9 17 60 180 465 1108 2512 5452 11299 22302 41912 75117 128739 211623 334624 510271 751957 1072471 +6 2 -2 -6 -10 -14 -18 -22 -26 -30 -34 -38 -42 -46 -50 -54 -58 -62 -66 -70 -74 +11 21 51 123 270 550 1073 2042 3808 6951 12433 21930 38539 68170 122065 221025 402057 728257 1302799 2287877 3929316 +11 24 51 94 158 269 509 1079 2406 5315 11292 22869 44167 81638 145052 248780 413429 667890 1051865 1618944 2440308 +11 9 8 11 21 41 74 123 191 281 396 539 713 921 1166 1451 1779 2153 2576 3051 3581 +21 46 95 196 399 782 1466 2650 4690 8266 14709 26617 49028 91734 173958 333777 646619 1260214 2457923 4768850 9152061 +-7 5 31 71 125 193 275 371 481 605 743 895 1061 1241 1435 1643 1865 2101 2351 2615 2893 +3 17 47 97 176 318 630 1394 3267 7653 17382 37962 79934 163342 326127 639455 1234643 2348417 4395537 8079943 14556772 +1 5 16 41 92 192 388 781 1600 3380 7367 16390 36645 81173 176337 373376 768211 1534183 2974410 5603063 10268194 +16 36 57 83 133 258 583 1386 3218 7059 14511 28075 51691 92031 161701 286836 524079 996507 1966292 3976716 8123144 +12 25 48 88 169 350 745 1545 3042 5654 9963 16846 27992 47642 87632 180451 410268 981779 2364538 5581148 12758639 +19 29 50 106 228 460 871 1570 2721 4555 7376 11558 17530 25746 36637 50542 67615 87705 110206 133874 156608 +-10 -19 -27 -29 -20 5 51 123 226 365 545 771 1048 1381 1775 2235 2766 3373 4061 4835 5700 +13 38 79 139 222 344 567 1074 2311 5237 11749 25392 52543 104430 200766 376821 698259 1293730 2427213 4656039 9165638 +19 38 69 120 196 308 498 884 1726 3509 7050 13696 25837 48275 91545 179170 362157 745928 1537467 3123904 6198218 +24 49 86 150 269 484 849 1431 2310 3579 5344 7724 10851 14870 19939 26229 33924 43221 54330 67474 82889 +7 18 29 40 51 62 73 84 95 106 117 128 139 150 161 172 183 194 205 216 227 +24 47 78 112 144 169 182 178 152 99 14 -108 -272 -483 -746 -1066 -1448 -1897 -2418 -3016 -3696 +9 2 2 29 110 272 529 867 1250 1704 2586 5226 13282 35444 90674 218126 495443 1071502 2223126 4450075 8629042 +1 6 25 67 149 308 617 1205 2297 4315 8109 15411 29632 57200 109894 209324 396293 750976 1435741 2782551 5463323 +14 25 52 116 250 505 956 1708 2902 4721 7396 11212 16514 23713 33292 45812 61918 82345 107924 139588 178378 +1 19 46 89 178 377 800 1650 3323 6656 13448 27446 56064 113192 223554 429189 798757 1440513 2519946 4283247 7087950 +23 33 54 103 195 353 629 1145 2178 4330 8843 18140 36696 72368 138340 255868 458041 794807 1339548 2197525 3516553 +13 32 51 66 79 100 142 209 281 305 207 -53 -353 -169 1826 8384 24597 59190 126291 247792 456431 +16 27 51 108 230 461 857 1486 2428 3775 5631 8112 11346 15473 20645 27026 34792 44131 55243 68340 83646 +12 4 4 27 97 261 612 1319 2671 5172 9783 18503 35622 70173 140365 281103 556102 1076588 2029158 3716051 6611871 +0 8 23 54 123 265 528 973 1674 2718 4205 6248 8973 12519 17038 22695 29668 38148 48339 60458 74735 +13 28 41 46 44 60 169 540 1521 3810 8783 19072 39490 78366 149266 272961 479501 810760 1325705 2115606 3347448 +10 36 89 189 375 724 1379 2596 4835 8954 16639 31352 60365 118985 239073 485798 989906 2008729 4039473 8025686 15726089 +14 21 37 76 152 279 471 742 1106 1577 2169 2896 3772 4811 6027 7434 9046 10877 12941 15252 17824 +4 23 54 97 150 204 247 301 532 1486 4523 12582 31599 73400 162073 348415 742439 1584669 3397580 7296726 15609169 +8 14 17 9 -18 -55 -47 148 812 2432 5777 11987 22674 40035 66977 107254 165616 247970 361553 515117 719126 +-6 -5 14 69 182 375 672 1127 1915 3561 7468 17075 40274 94194 214185 469888 992764 2021515 3974646 7563229 13962050 +-7 -6 3 28 83 197 442 997 2271 5123 11246 23837 48787 96856 187753 357880 674949 1265048 2361413 4389658 8112139 +17 29 52 93 175 349 710 1421 2749 5117 9176 15901 26715 43645 69514 108173 164777 246109 360956 520541 739015 +16 21 25 37 86 235 599 1379 2936 5956 11806 23271 46045 91750 184157 372288 758444 1558423 3229987 6742565 14131100 +21 44 72 97 115 134 191 389 964 2388 5507 11703 23056 42466 73676 121115 189455 282748 402978 547829 707433 +2 13 51 142 332 698 1374 2605 4842 8891 16129 28800 50404 86192 143780 233895 371266 575673 873167 1297474 1891596 +-3 -4 -4 9 56 172 416 886 1739 3216 5672 9611 15726 24944 38476 57872 85081 122516 173124 240461 328772 +19 25 33 48 84 189 495 1300 3199 7317 15775 32655 65938 131202 258381 503887 972651 1859993 3535757 6721174 12868440 +6 19 53 133 311 693 1480 3033 5981 11400 21100 38066 67108 115784 195669 324052 526152 837953 1309767 2010643 3033749 +6 23 54 104 195 376 732 1399 2599 4721 8508 15508 29189 57643 119845 259373 572956 1267205 2767030 5916226 12338927 +17 28 34 33 24 11 20 131 528 1584 4047 9514 21640 49058 112038 256981 586879 1323687 2933530 6373928 13574464 +-3 4 21 51 105 213 434 875 1742 3459 6904 13824 27504 53778 102483 189470 339299 588758 991359 1622977 2588811 +13 25 55 113 225 449 904 1831 3718 7546 15273 30806 61970 124436 249300 497110 982731 1917647 3679267 6920687 12739335 +2 7 17 44 106 227 437 772 1274 1991 2977 4292 6002 8179 10901 14252 18322 23207 29009 35836 43802 +17 23 28 34 56 131 336 832 1965 4491 10062 22220 48288 102684 212226 423765 813665 1496731 2628376 4386946 6911520 +-2 12 38 85 176 357 708 1352 2460 4252 7004 11119 17476 28672 52658 112029 265450 653240 1588186 3726829 8377872 +6 8 10 18 37 69 111 153 176 150 32 -236 -729 -1541 -2787 -4605 -7158 -10636 -15258 -21274 -28967 +19 32 67 132 238 408 692 1190 2083 3682 6534 11681 21272 39920 77557 155217 316419 649028 1326253 2681698 5343402 +9 13 15 14 11 13 45 185 643 1915 5078 12386 28533 63352 137456 293614 618821 1285549 2626241 5263674 10332631 +16 26 38 52 68 86 106 128 152 178 206 236 268 302 338 376 416 458 502 548 596 +15 17 15 0 -42 -124 -236 -296 -58 1059 4308 12301 30382 69227 149452 309246 616213 1184609 2198865 3943522 6838250 +13 34 77 158 292 502 849 1495 2813 5560 11131 21914 41768 76648 135403 230775 380629 609446 950113 1446046 2153684 +29 50 89 159 280 490 863 1537 2772 5090 9596 18641 37065 74350 148120 289547 551359 1019298 1828043 3182795 5387918 +14 20 36 72 149 317 676 1400 2764 5174 9200 15612 25419 39911 60704 89788 129578 182968 253388 344864 462081 +18 33 48 66 95 157 309 688 1613 3806 8824 19824 42825 88716 176442 338164 627848 1135839 2013700 3516158 6070647 +3 11 37 102 253 583 1273 2672 5439 10784 20859 39374 72595 131145 233723 415411 746339 1372141 2597305 5048170 9976569 +0 1 21 79 212 487 1024 2049 4009 7805 15242 29878 58635 114950 225182 442034 873022 1740613 3507271 7129617 14561582 +14 26 46 95 206 436 885 1716 3177 5654 9845 17260 31459 60807 124182 262286 559538 1186104 2478626 5095643 10316494 +-4 -1 13 47 112 219 374 578 848 1281 2193 4399 9800 22685 52674 121271 276057 620630 1376470 3008722 6478201 +-1 0 5 28 87 209 453 975 2173 4961 11234 24626 51794 104808 205998 398114 765319 1474902 2856323 5544028 10724189 +2 11 45 112 217 362 544 761 1051 1612 3096 7268 18426 46373 112435 261189 582408 1250505 2592783 5203456 10128151 +1 10 29 71 160 332 637 1159 2098 3994 8216 17889 39501 85564 179013 360790 703924 1341902 2529732 4780667 9176991 +-10 -20 -23 4 95 295 660 1257 2164 3470 5275 7690 10837 14849 19870 26055 33570 42592 53309 65920 80635 +11 9 21 59 135 261 449 711 1059 1505 2061 2739 3551 4509 5625 6911 8379 10041 11909 13995 16311 +1 19 51 97 157 231 319 421 537 667 811 969 1141 1327 1527 1741 1969 2211 2467 2737 3021 +-3 -1 10 39 104 238 513 1097 2359 5037 10484 21007 40314 74084 130675 221985 364481 580411 899214 1359143 2009116 +1 10 20 30 39 44 44 60 185 677 2101 5525 12816 27236 54922 108622 216493 441168 918078 1927684 4024457 +11 11 11 24 76 206 462 893 1537 2405 3461 4598 5610 6160 5744 3651 -1081 -9713 -23857 -45532 -77224 +18 22 26 28 26 25 41 99 234 523 1207 3022 7991 21246 55208 139195 341286 816868 1912760 4381912 9808620 +22 34 61 124 262 539 1047 1910 3313 5620 9728 17964 36115 77645 171868 378894 815640 1699206 3416575 6633036 12456092 +4 10 16 22 28 34 40 46 52 58 64 70 76 82 88 94 100 106 112 118 124 +5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 +9 8 21 69 176 372 699 1212 1959 2919 3883 4288 3066 -1343 -10535 -24783 -40075 -42542 1113 159039 557924 +1 16 60 158 358 738 1408 2507 4195 6640 10000 14400 19904 26482 33972 42037 50117 57376 62644 64354 60474 +20 22 21 17 10 0 -13 -29 -48 -70 -95 -123 -154 -188 -225 -265 -308 -354 -403 -455 -510 +-3 5 23 60 143 319 656 1258 2334 4412 8884 19231 43538 99304 222123 480607 1000995 2006303 3876685 7239966 13104153 +10 15 25 44 88 208 523 1256 2764 5551 10251 17566 28142 42364 60049 80014 99494 113383 113269 86232 13372 +13 37 81 153 272 480 861 1571 2883 5251 9397 16425 27966 46358 74865 117939 181529 273441 403753 585289 834156 +2 7 28 68 140 291 635 1395 2954 5915 11170 19978 34052 55655 87705 133889 198786 287999 408296 567760 775948 +20 28 50 96 174 294 475 763 1288 2415 5077 11414 25876 56981 119980 240885 463014 859349 1559953 2818936 5181974 +7 13 15 4 -22 -46 -20 147 601 1555 3301 6222 10804 17648 27482 41173 59739 84361 116395 157384 209070 +17 38 79 147 243 361 487 598 661 632 455 61 -633 -1725 -3329 -5576 -8615 -12614 -17761 -24265 -32357 +4 8 17 36 79 179 408 922 2076 4699 10679 24083 53127 113416 232994 459879 872908 1596882 2823181 4837214 8054279 +-6 -14 -17 -3 44 151 373 826 1744 3570 7093 13645 25374 45611 79351 133870 219502 350602 546723 834037 1247032 +16 17 11 6 33 172 590 1587 3655 7582 14694 27463 51007 96643 189932 388072 815806 1736311 3685345 7715308 15823521 +0 1 14 52 147 372 878 1951 4092 8121 15304 27500 47323 78312 125100 193571 290992 426105 609162 851884 1167323 +-8 -12 -16 -20 -24 -28 -32 -36 -40 -44 -48 -52 -56 -60 -64 -68 -72 -76 -80 -84 -88 +7 19 31 43 55 67 79 91 103 115 127 139 151 163 175 187 199 211 223 235 247 +18 32 52 91 175 357 745 1552 3186 6428 12816 25489 50979 102809 208305 420810 840554 1648848 3162100 5914471 10780879 +11 17 30 73 191 465 1027 2076 3901 6929 11845 19909 33795 59746 112848 229237 492797 1090457 2421002 5299149 11321357 +14 21 29 38 48 59 71 84 98 113 129 146 164 183 203 224 246 269 293 318 344 +-4 5 35 101 221 416 710 1130 1706 2471 3461 4715 6275 8186 10496 13256 16520 20345 24791 29921 35801 +7 24 54 104 190 348 660 1307 2673 5543 11461 23347 46542 90617 172651 323416 599235 1104514 2033496 3745154 6892958 +14 33 59 95 154 263 467 833 1454 2453 3987 6251 9482 13963 20027 28061 38510 51881 68747 89751 115610 +18 36 61 97 164 320 696 1557 3426 7359 15549 32578 67840 139937 284216 565080 1095282 2065110 3785205 6747735 11711788 +17 33 68 134 253 481 956 1980 4146 8531 17018 32923 62344 117095 220838 421203 812439 1575645 3047096 5829844 10969911 +0 -4 3 45 163 437 1033 2283 4804 9660 18569 34155 60243 102193 167267 265021 407712 610708 892887 1277009 1790043 +10 31 79 182 377 719 1314 2397 4488 8673 17071 33558 64819 121781 221434 388961 659958 1082315 1717031 2636830 3920909 +14 16 34 83 178 338 590 982 1624 2777 5002 9372 17764 33343 61654 113513 212633 414525 850169 1820632 3990833 +22 34 60 123 269 581 1201 2367 4472 8145 14347 24491 40682 66416 108613 182895 325854 621100 1250690 2590843 5381575 +12 22 52 117 235 441 816 1531 2906 5484 10120 18085 31185 51895 83508 130299 197704 292514 423084 599557 834103 +13 15 25 52 98 149 162 60 -243 -759 -1253 -927 2193 12653 41110 113380 292561 730027 1776413 4211078 9695696 +16 33 71 147 295 577 1094 1997 3498 5881 9513 14855 22473 33049 47392 66449 91316 123249 163675 214203 276635 +12 34 79 159 284 454 646 795 776 409 -471 -1813 -2921 -1652 6989 33242 96632 232776 504815 1022459 1973298 +-8 -5 5 22 46 77 115 160 212 271 337 410 490 577 671 772 880 995 1117 1246 1382 +27 45 65 79 88 116 228 556 1337 2967 6075 11621 21022 36310 60326 96954 151399 230513 343173 500715 717428 +19 29 35 31 11 -16 7 244 1058 3136 7629 16255 31258 55035 89131 132154 175973 199327 157687 -32129 -514491 +-4 -6 6 48 146 346 721 1368 2386 3824 5586 7278 7980 5924 -1943 -20534 -57360 -123458 -234538 -412380 -686514 +10 16 22 28 34 40 46 52 58 64 70 76 82 88 94 100 106 112 118 124 130 +-1 2 13 43 113 264 586 1280 2780 5992 12771 26881 55911 115042 234364 472995 946217 1877326 3695649 7218859 13985161 +12 33 65 110 170 247 343 460 600 765 957 1178 1430 1715 2035 2392 2788 3225 3705 4230 4802 +2 2 12 46 130 310 667 1358 2732 5616 11941 26010 56943 123223 260866 537596 1076622 2095565 3970036 7340823 13306956 +13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 +-5 0 10 23 41 87 236 675 1835 4679 11284 25922 56925 119712 241462 468036 873883 1575810 2751654 4665065 7697793 +24 48 97 178 306 515 878 1551 2863 5493 10828 21713 44020 89815 183426 372443 746638 1468994 2824479 5293880 9661890 +7 18 37 71 133 243 438 806 1571 3290 7299 16693 38385 87208 193646 417621 871759 1758470 3425433 6442527 11697805 +-3 -5 -7 -9 -11 -13 -15 -17 -19 -21 -23 -25 -27 -29 -31 -33 -35 -37 -39 -41 -43 +3 6 8 9 9 8 6 3 -1 -6 -12 -19 -27 -36 -46 -57 -69 -82 -96 -111 -127 +12 21 31 43 64 119 264 596 1264 2508 4796 9197 18226 37530 78957 165768 341020 680471 1311741 2441911 4396260 +4 3 5 28 113 330 780 1593 2922 4933 7791 11642 16591 22676 29838 37887 46464 54999 62665 68328 70493 +-3 -11 -15 -5 39 166 486 1225 2832 6203 13146 27299 55836 112460 222393 430337 812703 1495793 2682079 4687259 7991389 +2 15 44 105 228 460 868 1542 2598 4181 6468 9671 14040 19866 27484 37276 49674 65163 84284 107637 135884 +3 11 40 101 203 362 624 1102 2027 3813 7136 13027 22979 39068 64088 101700 156595 234671 343224 491153 689179 +8 14 31 75 163 315 572 1036 1948 3855 7982 17025 36728 78840 166482 343879 694468 1375852 2689261 5219099 10111301 +11 3 -7 -2 59 262 781 1951 4373 9055 17611 32574 57932 100100 169798 285943 484107 835051 1484409 2734358 5204293 +5 14 38 89 186 362 690 1343 2704 5543 11283 22391 42971 79763 144129 256634 458380 839057 1603913 3225958 6774521 +26 44 66 86 105 151 313 808 2113 5202 11927 25568 51546 98241 177780 306554 505084 796680 1204120 1743314 2412607 +11 33 60 102 190 391 841 1805 3768 7559 14517 26739 47549 82604 142745 251264 461497 896897 1837070 3892788 8345232 +1 11 30 55 97 192 415 917 2026 4480 9893 21594 46024 94927 188628 360754 664823 1183201 2039008 3411641 5556675 +9 8 8 4 -15 -66 -156 -237 -108 783 3719 11405 29158 66855 141981 284214 542091 992418 1753218 3001154 4994519 +5 5 17 55 129 252 459 846 1653 3444 7492 16579 36599 79643 169694 352720 713885 1405871 2693995 5025999 9137181 +0 13 44 102 195 329 521 849 1583 3473 8319 20037 46613 103696 221291 456385 916926 1807321 3514066 6764684 12917467 +-6 -11 -13 -4 32 126 332 745 1560 3245 6975 15596 35578 80698 178596 381901 786366 1559421 2983795 5522420 9912764 +-1 -3 -7 -5 31 163 501 1217 2559 4865 8577 14255 22591 34423 50749 72741 101759 139365 187337 247683 322655 +21 39 77 152 295 563 1051 1904 3329 5607 9105 14288 21731 32131 46319 65272 90125 122183 162933 214056 277439 +6 29 65 126 248 503 1024 2069 4175 8497 17505 36341 75339 154532 311548 615478 1191847 2269281 4269830 7987834 14947253 +20 40 73 127 227 424 804 1497 2686 4616 7603 12043 18421 27320 39430 55557 76632 103720 138029 180919 233911 +15 38 75 134 233 416 790 1593 3316 6923 14248 28714 56658 109863 210647 402612 774114 1510081 3005673 6111536 12652594 +7 5 15 45 96 157 201 191 120 139 873 4093 14036 39952 101162 237550 531921 1157605 2477551 5243665 10982708 +13 17 31 67 147 310 634 1286 2613 5287 10517 20341 38011 68484 119032 199984 325613 515181 794155 1195607 1761811 +17 33 54 81 115 157 208 269 341 425 522 633 759 901 1060 1237 1433 1649 1886 2145 2427 +28 54 99 175 307 547 991 1792 3153 5286 8362 12600 18924 31165 61765 144619 361520 893414 2115587 4769009 10261479 +20 36 69 139 273 505 876 1434 2234 3338 4815 6741 9199 12279 16078 20700 26256 32864 40649 49743 60285 +5 8 31 94 226 478 942 1781 3298 6123 11687 23304 48451 103329 221681 471406 985175 2015814 4035247 7910522 15218324 +27 35 51 98 222 513 1138 2401 4856 9517 18251 34532 64911 121863 229160 431651 812377 1521391 2822579 5167286 9306748 +12 18 24 30 36 42 48 54 60 66 72 78 84 90 96 102 108 114 120 126 132 +5 14 30 60 119 234 466 966 2094 4650 10290 22218 46247 92318 176623 324791 577635 1003771 1730224 3017395 5437035 +-4 2 15 37 71 129 250 540 1263 3047 7341 17400 40333 91193 200824 430390 897530 1822532 3608915 6983275 13237359 +24 39 59 84 114 149 189 234 284 339 399 464 534 609 689 774 864 959 1059 1164 1274 +6 8 15 26 40 56 73 90 106 120 131 138 140 136 125 106 78 40 -9 -70 -144 +5 12 38 98 215 420 760 1327 2319 4138 7527 13771 25077 45463 82903 154219 295579 584290 1184142 2442474 5104989 +15 20 30 67 165 370 740 1345 2267 3600 5450 7935 11185 15342 20560 27005 34855 44300 55542 68795 84285 +12 24 49 91 167 328 704 1596 3655 8207 17801 37071 74010 141751 260934 462706 792350 1313466 2112529 3303523 5032193 +7 6 2 -4 -4 22 111 328 805 1860 4298 10072 23590 54100 119775 254360 517539 1010538 1898906 3444916 6052608 +24 41 68 110 172 259 376 528 720 957 1244 1586 1988 2455 2992 3604 4296 5073 5940 6902 7964 +4 -2 -4 16 84 230 492 935 1688 2998 5296 9266 15904 26550 42872 66777 100220 144878 201652 269956 346748 +10 4 6 36 129 338 741 1461 2717 4950 9122 17381 34440 70266 145074 298276 604163 1199220 2330420 4443939 8357344 +-6 5 46 132 274 482 787 1296 2299 4470 9269 19793 42598 91531 195593 414745 871234 1811092 3723960 7574705 15246840 +14 29 56 116 256 575 1274 2734 5619 10989 20383 35781 59259 91989 131979 169563 179100 104581 -164174 -829374 -2243510 diff --git a/2023/09/part1/part1.go b/2023/09/part1/part1.go new file mode 100644 index 0000000..51532a0 --- /dev/null +++ b/2023/09/part1/part1.go @@ -0,0 +1,85 @@ + +package part1 + +import ( + "bufio" + "strings" + "strconv" + "os" + "errors" + "fmt" +) + +func main() { + reader := bufio.NewReader(os.Stdin); + total := 0; + for { + line, err := reader.ReadString('\n'); + if (err != nil) { + break + } + values, err := LineConv(line) + if err != nil { + fmt.Println(err) + return + } + next, err := Next(values) + if err != nil { + fmt.Println(err) + return + } + total += next; + fmt.Printf("%v => %v\n", values, next) + } + println(total) + return +} + +func Next(src []int) (int, error) { + if len(src) < 2 { + return 0, errors.New("not enough data!") + } + if IsZero(src) { + return 0, nil + } + deriv := Deriv(src) + nextDelta, err := Next(deriv) + if (err != nil) { + return 0, err + } + return src[len(src)-1] + nextDelta, nil +} + +func Deriv(src []int) (deriv []int) { + for i := range src { + if i == len(src)-1 { + break + } + deriv = append(deriv, src[i+1] - src[i]) + } + return +} + +func IsZero(src []int) bool { + res := true + for _,v := range src { + if v != 0 { + res = false + } + } + return res +} + +func LineConv(line string) ( []int, error ) { + strs := strings.Split(strings.Trim(line, "\n"), " ") + values := []int{}; + for _, str := range strs { + value, err := strconv.Atoi(str) + if (err != nil) { + return []int{}, err + } + values = append(values, value) + } + return values, nil; +} + diff --git a/2023/09/part1/part1_test.go b/2023/09/part1/part1_test.go new file mode 100644 index 0000000..118c7c7 --- /dev/null +++ b/2023/09/part1/part1_test.go @@ -0,0 +1,70 @@ + +package part1 + +import ( + "testing" + "reflect" +) + +func TestNextConst(t *testing.T) { + next, err := Next([]int{1, 1, 1}) + equal(t, err, nil) + equal(t, next, 1) + next, err = Next([]int{2, 2, 2}) + equal(t, err, nil) + equal(t, next, 2) +} + +func TestNextLinear(t *testing.T) { + next, err := Next([]int{0, 1, 2, 3}) + equal(t, err, nil) + equal(t, next, 4) +} + +func TestNextQuad(t *testing.T) { + next, err := Next([]int{0, 1, 4, 9, 16}) + equal(t, err, nil) + equal(t, next, 25) +} + +func TestNextBadList(t *testing.T) { + v, err := Next([]int{0, 5, 2}) + if err == nil { + t.Errorf("expected error, got %v", v) + } +} + +func TestDerivConst(t *testing.T) { + equal(t, Deriv([]int{1,1,1}), []int{0,0}) + equal(t, Deriv([]int{2,2,2}), []int{0,0}) +} + +func TestDerivLinear(t *testing.T) { + equal(t, Deriv([]int{0,1,2}), []int{1,1}) + equal(t, Deriv([]int{0,2,4}), []int{2,2}) +} + +func TestDerivQuad(t *testing.T) { + equal(t, Deriv([]int{0,1,4,9,16}), []int{1,3,5,7}) +} + +func TestIsZero(t *testing.T) { + equal(t, IsZero([]int{0}), true) + equal(t, IsZero([]int{0, 0}), true) + equal(t, IsZero([]int{1}), false) + equal(t, IsZero([]int{1, 1}), false) + equal(t, IsZero([]int{1, 0}), false) +} + +func TestLineConv(t *testing.T) { + r, err := LineConv("0 1 2 3") + equal(t, err, nil) + equal(t, r, []int{0, 1, 2, 3}) +} + +func equal(t *testing.T, actual any, target any) { + if !reflect.DeepEqual(actual, target) { + t.Errorf("expected %v, got %v", target, actual) + } +} + diff --git a/2023/09/part2/cmd/main.go b/2023/09/part2/cmd/main.go new file mode 100644 index 0000000..d820854 --- /dev/null +++ b/2023/09/part2/cmd/main.go @@ -0,0 +1,36 @@ + +package main + +import ( + "bufio" + "os" + "fmt" + "git.tristans.cloud/tristan/aoc/2023/09/part1" + "git.tristans.cloud/tristan/aoc/2023/09/part2/part2" +) + +func main() { + reader := bufio.NewReader(os.Stdin); + total := 0; + for { + line, err := reader.ReadString('\n'); + if (err != nil) { + break + } + values, err := part1.LineConv(line) + if err != nil { + fmt.Println(err) + return + } + next, err := part2.Next(values, true) + if err != nil { + fmt.Println(err) + return + } + total += next; + fmt.Printf("%v => %v\n", values, next) + } + println(total) + return +} + diff --git a/2023/09/part2/part2/part2.go b/2023/09/part2/part2/part2.go new file mode 100644 index 0000000..e808a9d --- /dev/null +++ b/2023/09/part2/part2/part2.go @@ -0,0 +1,28 @@ + +package part2 + +import ( + "errors" + "git.tristans.cloud/tristan/aoc/2023/09/part1" +) + +func Next(src []int, dir bool) (int, error) { + if len(src) < 2 { + return 0, errors.New("not enough data!") + } + if part1.IsZero(src) { + return 0, nil + } + deriv := part1.Deriv(src) + nextDelta, err := Next(deriv, dir) + if (err != nil) { + return 0, err + } + if dir { + return src[0] - nextDelta, nil + } else { + return src[len(src)-1] + nextDelta, nil + } +} + + diff --git a/2023/09/part2/part2/part2_test.go b/2023/09/part2/part2/part2_test.go new file mode 100644 index 0000000..9f56038 --- /dev/null +++ b/2023/09/part2/part2/part2_test.go @@ -0,0 +1,19 @@ + +package part2 +import ( + "testing" + "reflect" +) + +func TestPrev(t *testing.T) { + next, err := Next([]int{0,1,2,3}, true) + equal(t,err,nil) + equal(t,next,-1) +} + +func equal(t *testing.T, actual any, target any) { + if !reflect.DeepEqual(actual, target) { + t.Errorf("expected %v, got %v", target, actual) + } +} + diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..7b58f1d --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.tristans.cloud/tristan/aoc + +go 1.21.4 diff --git a/go.work b/go.work new file mode 100644 index 0000000..80b99d8 --- /dev/null +++ b/go.work @@ -0,0 +1,6 @@ +go 1.21.4 + +use ( + 2023/09 + 2023/08 +)