From a08f610e4e840dbc7e7178eddb3fbd232594e79b Mon Sep 17 00:00:00 2001 From: Lea Date: Sun, 10 Dec 2023 13:45:56 +0100 Subject: [PATCH] day 9 --- Cargo.lock | 8 ++ day_9/input.txt | 200 +++++++++++++++++++++++++++++++++++++++ day_9/part_1/Cargo.toml | 8 ++ day_9/part_1/src/main.rs | 28 ++++++ day_9/part_2/Cargo.toml | 8 ++ day_9/part_2/src/main.rs | 28 ++++++ 6 files changed, 280 insertions(+) create mode 100644 day_9/input.txt create mode 100644 day_9/part_1/Cargo.toml create mode 100644 day_9/part_1/src/main.rs create mode 100644 day_9/part_2/Cargo.toml create mode 100644 day_9/part_2/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 0ad4dbc..fd0a249 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -84,6 +84,14 @@ dependencies = [ "regex", ] +[[package]] +name = "day_9-1" +version = "0.1.0" + +[[package]] +name = "day_9-2" +version = "0.1.0" + [[package]] name = "memchr" version = "2.6.4" diff --git a/day_9/input.txt b/day_9/input.txt new file mode 100644 index 0000000..4697ff2 --- /dev/null +++ b/day_9/input.txt @@ -0,0 +1,200 @@ +20 27 37 68 149 321 638 1165 1983 3241 5344 9436 18430 38955 84735 182089 378446 755007 1444959 2658956 4719931 +4 27 79 177 347 630 1088 1811 2926 4609 7101 10729 15933 23300 33606 47867 67400 93895 129499 176913 239503 +-4 -7 0 27 90 214 433 798 1412 2529 4805 9906 21910 50370 116689 266897 596596 1298895 2755894 5713391 11616498 +-5 -4 5 30 83 173 302 472 711 1126 1991 3878 7839 15647 30104 55424 97699 165456 270313 427742 657947 +15 22 39 67 112 196 366 698 1293 2262 3697 5625 7942 10324 12112 12168 8699 -954 -20565 -55313 -112116 +17 21 20 14 13 42 150 428 1051 2390 5312 11943 27490 64328 150639 347692 782705 1708551 3607880 7368160 14566447 +3 3 14 53 138 287 515 832 1246 1781 2545 3957 7425 17167 44672 118854 307964 765351 1823752 4189940 9350701 +17 34 65 124 245 484 921 1670 2923 5098 9246 18017 37712 82293 180781 390506 820825 1676574 3340347 6532502 12625667 +16 22 38 85 205 474 1015 2011 3718 6478 10732 17033 26059 38626 55701 78415 108076 146182 194434 254749 329273 +27 34 32 28 35 67 137 258 455 822 1712 4243 11455 30681 78021 186257 418147 887818 1793976 3469902 6456747 +-5 -9 -17 -31 -57 -98 -134 -89 219 1164 3486 8664 19704 42763 90456 188572 389655 800117 1633181 3309339 6640985 +-6 -2 6 22 68 210 610 1614 3892 8665 18102 36079 69723 132632 251579 480262 926979 1809393 3561583 7041793 13934047 +22 32 47 74 132 268 583 1277 2734 5694 11603 23299 46291 91035 176832 338307 635930 1172784 2120867 3761756 6548610 +14 11 4 0 23 122 376 896 1824 3329 5600 8836 13233 18968 26180 34948 45266 57015 69932 83576 97291 +-7 -4 11 42 90 153 226 301 367 410 413 356 216 -33 -420 -977 -1739 -2744 -4033 -5650 -7642 +8 22 37 53 70 88 107 127 148 170 193 217 242 268 295 323 352 382 413 445 478 +8 15 33 68 126 213 335 498 708 971 1293 1680 2138 2673 3291 3998 4800 5703 6713 7836 9078 +10 19 25 39 88 224 547 1247 2671 5424 10518 19590 35219 61383 104110 172392 279448 444441 694775 1069121 1621346 +17 35 59 89 125 167 215 269 329 395 467 545 629 719 815 917 1025 1139 1259 1385 1517 +18 26 36 49 69 103 161 256 404 624 938 1371 1951 2709 3679 4898 6406 8246 10464 13109 16233 +15 15 16 24 51 123 296 690 1560 3446 7499 16197 34897 75110 161200 343676 724844 1507133 3082401 6194946 12238162 +3 2 18 80 232 548 1176 2436 5009 10267 20811 41326 79984 150935 279101 509802 928087 1696552 3126608 5807524 10831256 +19 48 86 133 202 324 562 1050 2087 4353 9399 20728 46064 101833 221471 469919 967540 1927762 3714504 6929680 12552949 +3 18 58 146 315 609 1092 1877 3193 5525 9902 18488 35775 70925 142247 285635 570519 1130520 2223550 4351174 8495811 +11 13 17 30 69 166 383 854 1884 4158 9159 19992 43016 91087 189942 390485 791705 1581963 3110809 6009806 11389639 +16 26 41 62 96 167 341 770 1757 3841 7898 15251 27779 48012 79196 125309 191006 281468 402127 558236 754250 +19 44 91 173 303 488 720 963 1150 1248 1540 3446 11535 38023 112311 300545 744743 1739374 3878135 8329581 17344593 +6 28 73 153 280 466 723 1063 1498 2040 2701 3493 4428 5518 6775 8211 9838 11668 13713 15985 18496 +-3 5 19 34 55 123 352 989 2535 6018 13612 29979 65014 139164 293304 606554 1227956 2432714 4722996 9011583 16962464 +25 38 65 132 289 619 1242 2314 4021 6566 10143 14886 20773 27455 33968 38272 36545 22142 -15891 -94880 -241319 +16 35 82 176 338 586 938 1441 2267 3967 8066 18336 43337 101244 228728 496991 1040394 2107115 4147882 7969376 14995196 +13 12 3 -22 -70 -132 -143 94 1040 3664 9939 23901 53904 117269 249461 521429 1071147 2159336 4266043 8256444 15664866 +12 28 41 51 64 105 252 703 1889 4646 10458 21781 42455 78207 137243 230921 374490 587872 896455 1331855 1932594 +4 10 26 76 197 432 824 1421 2315 3764 6487 12281 25193 53603 113760 235599 472106 914162 1713780 3120070 5534273 +12 13 27 66 151 322 646 1227 2237 4021 7393 14341 29496 62884 134661 282749 574696 1126211 2132153 3924766 7096019 +5 14 45 116 253 486 853 1427 2396 4265 8331 17747 39809 90691 204933 453955 981451 2069976 4264481 8598322 17000473 +6 17 49 118 244 455 793 1322 2139 3400 5399 8794 15207 28745 59709 133243 308500 718919 1652621 3705386 8059342 +5 13 21 29 37 45 53 61 69 77 85 93 101 109 117 125 133 141 149 157 165 +11 9 7 9 28 102 328 932 2407 5764 12956 27558 55820 108257 202030 364651 640475 1104197 1892757 3283933 5886380 +18 23 28 45 102 247 549 1101 2046 3674 6689 12858 26513 57943 130862 298300 675046 1500965 3259042 6885827 14130836 +6 9 26 79 195 401 717 1145 1652 2145 2436 2195 889 -2295 -8545 -19539 -37582 -65767 -108162 -170025 -258049 +7 18 30 48 84 159 301 547 971 1785 3603 8023 18767 43713 98233 210279 427579 827040 1525904 2693238 4558802 +13 34 82 185 392 781 1469 2625 4494 7461 12240 20404 35749 67534 137680 295916 650244 1425979 3076751 6488342 13346755 +10 16 32 77 177 381 802 1708 3700 8036 17198 35849 72377 141274 266713 488081 869443 1518170 2625875 4562765 8095270 +18 35 77 171 358 690 1233 2099 3550 6245 11736 23363 47775 97493 195413 383266 738390 1407635 2675155 5094127 9733640 +10 21 45 100 222 484 1028 2110 4158 7843 14163 24540 40930 65946 102994 156422 231682 335505 476089 663300 908886 +20 36 52 68 85 103 119 125 106 38 -114 -398 -877 -1631 -2759 -4381 -6640 -9704 -13768 -19056 -25823 +15 25 53 123 282 614 1255 2403 4329 7428 12411 20847 36462 68001 135317 282219 603580 1302299 2807472 6014465 12759931 +27 42 69 120 203 324 501 796 1371 2574 5061 9960 19083 35192 62325 106188 174619 278130 430533 649656 958155 +12 24 57 133 287 581 1125 2104 3816 6735 11626 19757 33277 55860 93754 157422 264020 441026 731415 1200869 1947619 +2 11 28 52 80 100 74 -99 -658 -2109 -5402 -12105 -24466 -45216 -77019 -121735 -180245 -254401 -352790 -498159 -717505 +-6 -14 -19 -15 -1 11 -19 -177 -590 -1339 -2177 -1833 3547 23781 81923 229823 581042 1379136 3135721 6901573 14782879 +1 -1 4 30 113 323 773 1619 3047 5250 8410 12717 18479 26404 38167 57412 91381 153409 266576 468864 820229 +14 33 68 130 240 437 803 1521 2993 6071 12508 25844 53168 108682 221008 448192 908116 1838649 3712952 7453106 14812604 +12 39 84 163 303 552 1001 1815 3273 5827 10207 17623 30146 51388 87646 149727 255730 435127 734558 1225835 2016737 +2 1 -2 4 37 115 255 492 937 1915 4278 10089 24036 56175 126933 275741 575228 1153605 2228718 4158266 7511879 +0 -5 -11 -18 -26 -35 -45 -56 -68 -81 -95 -110 -126 -143 -161 -180 -200 -221 -243 -266 -290 +14 35 64 97 138 224 469 1129 2700 6087 12926 26210 51489 99143 188679 356860 672998 1267279 2381956 4461119 8303016 +21 43 81 148 274 518 987 1869 3489 6401 11538 20459 35757 61719 105343 177791 296249 485915 781363 1225730 1864912 +10 12 28 67 136 240 382 563 782 1036 1320 1627 1948 2272 2586 2875 3122 3308 3412 3411 3280 +26 47 76 109 133 136 136 241 762 2414 6656 16240 36061 74425 144880 268786 478834 823761 1374548 2232431 3539101 +20 39 69 121 220 405 729 1259 2076 3275 4965 7269 10324 14281 19305 25575 33284 42639 53861 67185 82860 +5 -4 -16 -19 23 183 584 1412 2929 5486 9536 15647 24515 36977 54024 76814 106685 145168 194000 255137 330767 +10 22 45 71 102 172 372 888 2086 4727 10479 23027 50302 108739 231208 481692 982578 1965788 3869001 7516391 14455222 +-2 6 16 34 77 173 361 691 1224 2032 3198 4816 6991 9839 13487 18073 23746 30666 39004 48942 60673 +8 21 45 84 153 295 619 1367 3015 6410 12942 24747 44934 77826 129202 206524 319130 478371 697667 992454 1379991 +12 15 24 48 111 262 589 1245 2504 4879 9361 17910 34518 67605 135429 277944 581648 1229163 2593586 5410376 11078421 +21 44 92 172 300 513 894 1621 3060 5949 11782 23632 47913 98092 202343 418983 866943 1784698 3641988 7347492 14627346 +4 8 15 33 70 134 233 375 568 820 1139 1533 2010 2578 3245 4019 4908 5920 7063 8345 9774 +13 28 46 75 136 275 586 1245 2555 5002 9322 16579 28254 46345 73478 113029 169257 247448 354070 496939 685396 +8 16 21 20 20 66 291 995 2759 6600 14182 28140 52701 95100 168988 302497 556594 1065160 2119219 4337860 9004002 +24 35 46 57 68 79 90 101 112 123 134 145 156 167 178 189 200 211 222 233 244 +25 35 48 69 113 213 427 846 1602 2863 4788 7418 10530 13623 16493 21355 38263 96755 268312 706483 1714519 +17 25 40 59 72 74 94 244 791 2255 5536 12073 24038 44568 78038 130378 209437 325397 491240 723271 1041700 +8 27 52 77 107 180 405 1030 2573 6083 13647 29318 60695 121415 234781 438594 790906 1375767 2306978 3726231 5789631 +0 -4 -8 -11 -13 -15 -19 -28 -46 -78 -130 -209 -323 -481 -693 -970 -1324 -1768 -2316 -2983 -3785 +14 40 79 132 200 284 385 504 642 800 979 1180 1404 1652 1925 2224 2550 2904 3287 3700 4144 +3 13 49 127 267 505 928 1756 3502 7241 15016 30421 59469 112048 204697 366250 649321 1152977 2065819 3744979 6856771 +20 41 76 140 272 546 1082 2057 3716 6383 10472 16498 25088 36992 53094 74423 102164 137669 182468 238280 307024 +11 31 67 129 233 413 744 1378 2589 4813 8655 14817 23879 35839 49288 60062 59175 29795 -57021 -248167 -616291 +2 5 5 -2 -11 7 137 582 1780 4624 10881 24008 50759 104315 210218 417294 817358 1580611 3019953 5710186 10713041 +15 42 85 153 259 414 613 809 882 636 -98 -1107 -948 4760 26432 85729 223857 514214 1080987 2125697 3964145 +27 37 54 91 176 376 836 1843 3926 8008 15644 29419 53651 95655 167984 292281 505661 870903 1492178 2538579 4278362 +3 2 14 62 177 410 873 1829 3852 8082 16622 33196 64373 122073 228881 429180 811769 1554463 3010308 5872865 11493045 +-1 8 22 49 107 234 515 1131 2440 5118 10429 20785 40964 80806 161156 326760 673732 1407131 2960311 6240492 13130908 +13 37 73 132 247 495 1031 2134 4265 8137 14797 25720 42915 69043 107547 162794 240229 346541 489841 679852 928111 +3 9 35 91 182 305 440 533 479 133 -590 -1416 -1036 4215 22707 71418 182091 410553 850349 1652129 3050554 +5 14 41 109 257 545 1056 1900 3245 5429 9241 16494 31045 60442 118392 228243 427653 774576 1354625 2289771 3748201 +22 41 84 171 341 664 1249 2245 3835 6245 9852 15616 26362 50064 107549 249506 592292 1390265 3176508 7027153 15041771 +21 37 70 141 273 489 820 1345 2302 4324 8869 18946 40334 83728 168751 331726 640755 1224327 2323784 4386019 8221375 +11 29 52 84 150 311 677 1411 2716 4800 7835 12005 17960 28529 53725 123498 317373 828659 2095738 5057450 11628390 +-7 2 35 99 206 383 682 1190 2039 3416 5573 8837 13620 20429 29876 42688 59717 81950 110519 146711 191978 +27 41 55 69 83 97 111 125 139 153 167 181 195 209 223 237 251 265 279 293 307 +29 57 107 185 291 418 558 714 914 1217 1692 2343 2968 3045 2097 1973 14907 86797 357329 1203945 3567193 +18 39 70 118 194 315 523 937 1869 4062 9141 20400 44080 91349 181343 346006 638320 1147229 2025708 3543822 6187370 +9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81 85 89 +25 49 91 157 267 474 902 1817 3745 7651 15193 29065 53443 94548 161340 266357 426713 665269 1011991 1505509 2194891 +19 42 74 115 165 224 292 369 455 550 654 767 889 1020 1160 1309 1467 1634 1810 1995 2189 +-6 3 35 116 286 599 1123 1940 3146 4851 7179 10268 14270 19351 25691 33484 42938 54275 67731 83556 102014 +17 43 82 142 251 482 1004 2177 4723 10038 20783 42032 83501 163816 318601 615847 1185556 2278005 4379809 8445840 16359366 +18 30 49 81 147 309 711 1640 3616 7521 14771 27518 48837 82802 134281 208179 307726 431240 566589 682327 714183 +26 50 79 121 192 322 573 1070 2046 3902 7283 13171 22996 38766 63217 99984 153794 230682 338231 485837 685000 +5 15 44 117 281 615 1251 2418 4536 8424 15754 30007 58431 115999 233360 472667 958563 1937393 3887116 7715069 15102849 +0 11 25 35 27 -22 -135 -305 -434 -231 941 4279 11825 26832 54221 101139 177628 297415 478833 745883 1129447 +2 4 2 -14 -58 -144 -282 -465 -611 -382 1255 6932 22543 60062 142029 308349 626196 1203976 2210480 3900550 6648788 +12 11 25 67 144 259 415 618 880 1235 1821 3185 7204 19510 55281 152063 396436 976543 2280697 5074627 10807800 +28 51 81 117 172 285 533 1057 2140 4416 9366 20405 45139 99858 218155 466901 974912 1982857 3927731 7582149 14278570 +14 33 67 125 240 494 1059 2269 4754 9703 19392 38232 74795 145649 282580 546333 1053219 2027442 3904890 7539252 14609627 +-5 2 16 32 43 40 12 -54 -173 -362 -640 -1028 -1549 -2228 -3092 -4170 -5493 -7094 -9008 -11272 -13925 +-2 -5 -8 -11 -14 -17 -20 -23 -26 -29 -32 -35 -38 -41 -44 -47 -50 -53 -56 -59 -62 +10 22 48 86 137 220 398 817 1772 3839 8150 16939 34551 69183 135716 260100 485870 883500 1563444 2693868 4524245 +13 34 66 102 135 174 268 530 1152 2416 4758 9067 17654 36798 82618 193475 454551 1044238 2318290 4957436 10218785 +17 24 25 18 1 -28 -71 -130 -207 -304 -423 -566 -735 -932 -1159 -1418 -1711 -2040 -2407 -2814 -3263 +8 22 52 105 204 397 766 1441 2624 4628 7936 13285 21780 35043 55402 86125 131704 198194 293612 428401 615964 +7 11 22 52 112 218 415 825 1733 3747 8113 17360 36649 76602 159139 329145 676839 1378707 2768852 5457396 10517442 +9 4 9 42 120 256 459 745 1168 1890 3341 6587 14155 31834 72552 164687 369870 821090 1804116 3931014 8508337 +10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 +24 48 82 136 234 413 725 1262 2251 4319 9119 20651 47835 109262 241720 515417 1061543 2123375 4153165 7998055 15256497 +23 35 61 124 255 489 857 1374 2023 2735 3365 3664 3247 1557 -2175 -8974 -20169 -37445 -62899 -99100 -149153 +22 41 78 146 264 456 750 1177 1770 2563 3590 4884 6476 8394 10662 13299 16318 19725 23518 27686 32208 +7 15 31 52 84 162 375 904 2092 4576 9522 19015 36667 68517 124308 219237 376285 629245 1026577 1636230 2551582 +-3 5 28 68 129 238 491 1134 2689 6135 13154 26452 50165 90360 155641 257870 413013 642121 972456 1438772 2084761 +23 34 45 50 39 7 -20 66 552 2097 6131 15692 37168 83837 182833 388387 806166 1636709 3251293 6323508 12060892 +16 36 85 184 359 643 1097 1875 3378 6569 13554 28588 59785 122099 242811 472219 905244 1725550 3294687 6328080 12232483 +11 8 1 3 50 210 595 1384 2876 5610 10609 19816 36774 67533 121610 212538 357061 571296 861109 1202445 1505302 +13 23 39 75 149 283 503 839 1325 1999 2903 4083 5589 7475 9799 12623 16013 20039 24775 30299 36693 +12 24 47 83 140 234 401 745 1566 3647 8857 21386 50220 113956 249835 530055 1090204 2177338 4229335 8003477 14781872 +13 27 57 124 261 521 1003 1900 3573 6660 12243 22128 39369 69355 122233 218478 401668 767172 1524740 3130947 6561240 +12 6 -2 -6 13 106 394 1146 2939 6981 15748 34216 72219 148943 301453 600718 1181242 2294672 4404366 8347814 15608221 +-4 5 23 55 117 242 482 911 1645 2922 5354 10610 23065 53448 126448 296066 676292 1502685 3257185 6922817 14503427 +6 24 56 111 205 374 701 1358 2662 5145 9642 17408 30285 50953 83315 133085 208670 322462 492684 745965 1120853 +-1 -8 -18 -27 -19 44 232 657 1483 2936 5314 8997 14457 22268 33116 47809 67287 92632 125078 166021 217029 +19 32 47 83 169 338 620 1033 1583 2309 3457 5954 12506 29912 73667 176845 407154 900237 1926642 4030356 8319866 +0 -1 2 24 87 220 459 847 1434 2277 3440 4994 7017 9594 12817 16785 21604 27387 34254 42332 51755 +22 42 76 134 238 442 860 1694 3261 6052 10930 19703 36514 70804 143056 295119 607567 1227060 2406625 4560440 8330877 +6 19 38 67 106 146 161 93 -163 -743 -1699 -2667 -2137 3932 24498 77271 194560 431823 879752 1680879 3051856 +6 1 -11 -32 -64 -109 -169 -246 -342 -459 -599 -764 -956 -1177 -1429 -1714 -2034 -2391 -2787 -3224 -3704 +6 24 62 135 268 511 963 1805 3351 6153 11264 20917 40203 80992 170652 370646 814772 1785142 3858174 8175991 16934838 +9 14 15 23 65 183 434 895 1677 2952 4997 8259 13445 21641 34464 54251 84289 129090 194715 289151 422745 +12 12 17 32 52 59 30 -23 62 857 3851 12347 32954 77999 169461 345698 673819 1274145 2371036 4400773 8240255 +8 26 59 123 254 522 1045 2003 3652 6338 10511 16739 25722 38306 55497 78475 108608 147466 196835 258731 335414 +14 25 37 52 72 99 135 182 242 317 409 520 652 807 987 1194 1430 1697 1997 2332 2704 +8 17 51 130 280 533 927 1499 2259 3128 3818 3627 1117 -6362 -23344 -57162 -119158 -226245 -402883 -683536 -1115682 +5 0 -5 -10 -15 -20 -25 -30 -35 -40 -45 -50 -55 -60 -65 -70 -75 -80 -85 -90 -95 +16 24 53 125 268 523 960 1703 2964 5086 8595 14261 23168 36793 57094 86607 128552 186948 266737 373917 515684 +0 11 39 86 152 238 358 570 1047 2231 5152 12067 27729 61946 134874 288184 608787 1279027 2681776 5617806 11749991 +2 17 38 63 98 171 357 817 1854 3989 8060 15347 27726 47855 79395 127269 197962 299865 443666 642791 913898 +-3 -1 22 91 254 601 1296 2643 5230 10236 20061 39578 78560 156283 310062 610697 1189695 2285953 4323660 8038897 14680254 +16 26 41 61 83 109 163 330 843 2255 5742 13590 29924 61740 120302 222965 395482 674848 1112727 1779499 2768953 +-3 -1 1 2 2 8 55 245 806 2188 5258 11743 25205 53010 109960 224508 448951 876381 1671371 3132812 5835184 +8 23 42 65 92 123 158 197 240 287 338 393 452 515 582 653 728 807 890 977 1068 +12 26 55 121 262 542 1076 2085 4016 7788 15255 30014 58754 113512 215625 403112 745125 1370694 2525600 4683759 8764859 +16 22 39 86 202 470 1061 2306 4804 9574 18259 33390 58718 99622 163601 260858 404984 613750 910015 1322758 1888242 +3 -1 -4 2 45 194 600 1565 3652 7877 16093 31820 62061 121198 239117 477704 963620 1952404 3952501 7963359 15929276 +18 32 66 126 217 358 614 1165 2456 5518 12633 28650 63456 136378 283656 570613 1110810 2095404 3837272 6836446 11876343 +9 4 10 55 189 499 1129 2317 4491 8520 16301 31984 64303 130730 264639 527768 1033060 1989936 3800601 7273095 14095648 +8 8 19 52 118 228 393 624 932 1328 1823 2428 3154 4012 5013 6168 7488 8984 10667 12548 14638 +11 12 21 58 163 407 903 1817 3379 5894 9753 15444 23563 34825 50075 70299 96635 130384 173021 226206 291795 +25 35 56 114 253 554 1184 2490 5153 10417 20408 38558 70149 122992 208256 341462 543657 842783 1275256 1887770 2739341 +0 4 26 74 165 336 652 1219 2232 4136 8065 16867 37252 83972 187560 408192 859964 1752700 3462904 6652432 12463947 +16 24 32 42 56 76 104 142 192 256 336 434 552 692 856 1046 1264 1512 1792 2106 2456 +20 36 55 87 157 324 720 1626 3617 7839 16546 34151 69274 138670 274601 538351 1044434 2002994 3792481 7081643 13030179 +16 36 68 128 238 422 702 1095 1612 2260 3048 3998 5162 6646 8642 11469 15624 21844 31180 45084 65510 +1 2 7 29 95 252 583 1238 2484 4793 9027 16854 31651 60333 116818 228284 446268 866729 1668144 3188068 6083156 +7 8 19 58 156 379 880 2003 4465 9640 19971 39569 75172 137917 246978 437345 776462 1399243 2580166 4878067 9419163 +4 11 18 25 32 39 46 53 60 67 74 81 88 95 102 109 116 123 130 137 144 +25 38 47 51 59 105 282 806 2131 5169 11747 25589 54389 113996 236430 484466 976949 1930936 3729311 7025807 12903527 +7 13 35 93 226 499 1009 1900 3409 5984 10551 19077 35710 69027 136373 272063 542547 1073795 2099547 4044233 7662010 +12 27 42 57 72 87 102 117 132 147 162 177 192 207 222 237 252 267 282 297 312 +17 32 73 153 282 478 795 1376 2547 4975 9915 19564 37520 69307 122869 208853 340389 531930 796533 1140739 1555942 +-4 1 19 55 122 263 586 1324 2957 6474 13923 29516 61757 127404 258670 516101 1011346 1947023 3685771 6868325 12612372 +10 5 -3 -17 -32 -15 125 579 1690 4010 8372 16059 29366 53376 100926 205112 448344 1025855 2378223 5458349 12255366 +11 6 11 47 160 433 1003 2089 4031 7333 12704 21120 34025 54019 86869 146639 267527 529204 1107981 2375353 5080378 +4 15 30 50 92 216 566 1425 3284 6925 13518 24732 42860 70958 112998 174035 260388 379835 541822 757686 1040892 +11 35 84 184 381 754 1441 2687 4927 8921 15962 28182 48985 83640 140071 229885 369683 582703 900848 1367156 2038773 +23 39 68 126 244 489 1001 2052 4148 8225 16048 31040 60018 116838 230015 458458 923363 1871418 3797030 7672793 15373262 +9 35 73 123 185 259 345 443 553 675 809 955 1113 1283 1465 1659 1865 2083 2313 2555 2809 +7 3 -6 -20 -37 -39 45 417 1569 4597 11795 27732 61143 128192 258080 502714 953419 1769707 3228184 5804032 10303323 +-8 1 21 47 85 173 410 991 2240 4632 8812 15673 26671 44764 76701 137899 261880 517251 1036559 2063107 4024049 +11 17 25 34 47 76 156 370 888 2028 4353 8830 17114 32132 59465 110919 214006 436724 949858 2176195 5130226 +5 13 28 56 112 234 518 1196 2787 6356 13918 29023 57554 108763 196560 341057 570353 922527 1447784 2210674 3292276 +8 23 62 139 266 452 719 1145 1947 3638 7355 15599 33920 74651 164910 363262 793598 1712537 3640556 7611047 15631418 +13 33 74 157 309 557 919 1396 1977 2680 3680 5647 10573 23660 57337 139252 327237 735875 1581526 3255625 6439893 +3 2 1 11 51 144 311 558 852 1090 1092 721 399 2636 15873 63221 200974 555710 1395269 3259282 7191730 +10 20 39 72 124 200 305 444 622 844 1115 1440 1824 2272 2789 3380 4050 4804 5647 6584 7620 +10 14 21 31 44 60 79 101 126 154 185 219 256 296 339 385 434 486 541 599 660 +15 22 50 127 306 692 1486 3056 6053 11595 21551 38989 68939 119809 206136 353922 610671 1063484 1870260 3311259 5871060 +24 34 56 108 216 415 750 1277 2064 3192 4756 6866 9648 13245 17818 23547 30632 39294 49776 62344 77288 +5 17 30 46 76 142 279 537 983 1703 2804 4416 6694 9820 14005 19491 26553 35501 46682 60482 77328 +23 45 79 131 216 375 709 1439 3021 6384 13424 27987 57720 117371 234388 458043 873949 1627234 2961030 5285139 9308620 +4 12 28 69 170 394 844 1672 3078 5290 8514 12841 18096 23612 27910 28264 20128 -3600 -53504 -144795 -298706 +6 8 20 54 137 327 750 1678 3681 7900 16508 33465 65751 125404 232929 423014 754028 1323524 2292968 3926204 6647785 +15 34 74 142 253 445 805 1515 2932 5721 11061 20948 38662 69645 123582 219880 402005 773192 1580388 3400958 7537619 +14 18 36 88 200 404 738 1246 1978 2990 4344 6108 8356 11168 14630 18834 23878 29866 36908 45120 54624 +7 21 33 38 38 51 132 432 1343 3807 9915 24004 54595 117722 242497 480149 918267 1702557 3069065 5390478 9240728 +8 4 0 -4 -8 -12 -16 -20 -24 -28 -32 -36 -40 -44 -48 -52 -56 -60 -64 -68 -72 +23 34 45 56 67 78 89 100 111 122 133 144 155 166 177 188 199 210 221 232 243 +11 24 57 133 289 574 1056 1855 3226 5723 10482 19668 37138 69379 126787 225360 388885 651706 1062167 1686831 2615583 +8 18 38 65 105 191 414 983 2353 5493 12414 27166 57701 119382 241623 480297 940194 1813772 3444082 6419595 11703885 +5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 diff --git a/day_9/part_1/Cargo.toml b/day_9/part_1/Cargo.toml new file mode 100644 index 0000000..3ae6e2e --- /dev/null +++ b/day_9/part_1/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day_9-1" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/day_9/part_1/src/main.rs b/day_9/part_1/src/main.rs new file mode 100644 index 0000000..b669ccd --- /dev/null +++ b/day_9/part_1/src/main.rs @@ -0,0 +1,28 @@ +fn main() { + let input = include_str!("../../input.txt"); + let mut result: i32 = 0; + + for line in input.lines() { + let mut lists: Vec> = vec![line.split(" ").map(|num| num.parse::().unwrap()).collect()]; + + while lists.last().unwrap().iter().filter(|i| i != &&0).count() > 0 { + let current_list = lists.last().unwrap(); + let mut new_list: Vec = vec![]; + for i in 1..current_list.len() { + new_list.push(current_list[i] - current_list[i - 1]); + } + + lists.push(new_list); + } + + lists.last_mut().unwrap().push(0); + for i in (1..lists.len()).rev() { + let new_val = lists[i-1].last().unwrap() + lists[i].last().unwrap(); + lists.get_mut(i-1).unwrap().push(new_val); + } + + result += lists[0].last().unwrap(); + } + + println!("Result: {result}"); +} diff --git a/day_9/part_2/Cargo.toml b/day_9/part_2/Cargo.toml new file mode 100644 index 0000000..6f32a1d --- /dev/null +++ b/day_9/part_2/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day_9-2" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/day_9/part_2/src/main.rs b/day_9/part_2/src/main.rs new file mode 100644 index 0000000..8e18b33 --- /dev/null +++ b/day_9/part_2/src/main.rs @@ -0,0 +1,28 @@ +fn main() { + let input = include_str!("../../input.txt"); + let mut result: i32 = 0; + + for line in input.lines() { + let mut lists: Vec> = vec![line.split(" ").map(|num| num.parse::().unwrap()).collect()]; + + while lists.last().unwrap().iter().filter(|i| i != &&0).count() > 0 { + let current_list = lists.last().unwrap(); + let mut new_list: Vec = vec![]; + for i in 1..current_list.len() { + new_list.push(current_list[i] - current_list[i - 1]); + } + + lists.push(new_list); + } + + lists.last_mut().unwrap().insert(0, 0); + for i in (1..lists.len()).rev() { + let new_val = lists[i-1].first().unwrap() - lists[i].first().unwrap(); + lists.get_mut(i-1).unwrap().insert(0, new_val); + } + + result += lists[0].first().unwrap(); + } + + println!("Result: {result}"); +}