From 7b19a53f660a8529215d9418df8e698fc021e8aa Mon Sep 17 00:00:00 2001 From: Kalle Struik Date: Thu, 1 Dec 2022 11:58:44 +0100 Subject: [PATCH] Day 1 --- input/01.txt | 2249 +++++++++++++++++++++++++++++++++++++++++++++++ src/bin/01_1.rs | 30 + src/bin/01_2.rs | 35 + 3 files changed, 2314 insertions(+) create mode 100644 input/01.txt create mode 100644 src/bin/01_1.rs create mode 100644 src/bin/01_2.rs diff --git a/input/01.txt b/input/01.txt new file mode 100644 index 0000000..113b5ca --- /dev/null +++ b/input/01.txt @@ -0,0 +1,2249 @@ +4887 +9307 +8895 +8136 +6292 +10177 +4077 +8228 + +5533 +7981 +5396 +4909 +5657 +7587 +9651 +1583 +8058 + +5201 +4782 +5956 +5327 +2029 +3455 +6148 +5468 +2177 +5352 +5373 +5442 +4888 + +36630 +9196 + +28629 + +9252 +1098 +9842 +7347 +3616 +5157 +8546 + +8031 +7718 +6690 +7819 +10921 +12059 +10334 + +3455 +1687 +3740 +2666 +6672 +3264 +4330 +4673 +5550 +1754 +4161 +2764 +6355 + +2711 +3232 +1429 +2381 +5990 +4482 +3091 +2745 +1886 +5648 +4776 +2696 +2846 +4177 +5781 + +6379 +12826 +3706 +12650 +5875 +11396 + +10381 +2204 +5950 +11465 +11501 +13306 + +4006 +6635 +5139 +5290 +4562 +5558 +2788 +1242 +5308 +6704 +6858 +3751 + +3574 +5601 +4492 +4795 +2135 +3295 +6150 +4786 +6761 +5098 +6646 +5839 +1989 + +14468 +13500 +11544 +2195 +6282 + +1400 +3519 +6010 +4063 +4077 +1583 +2044 +5089 +3588 +6061 +1634 +1358 +2241 +2351 +6075 + +2658 +5979 +4727 +4991 +2198 +4491 +2206 +2601 +3637 +1955 +1618 +5849 +4662 +2457 +2479 + +7450 +2813 +1678 +5678 +6688 +3338 +3708 +4898 +4542 +4800 +3127 +3338 + +2747 +6148 +6301 +6097 +6988 +2280 +4093 +8031 +4865 +7293 +1528 + +7851 +3366 +10761 +12012 + +7487 +1457 +3109 +7722 +6730 +1528 +8678 +5243 +3434 +7351 + +7661 +2803 +7796 +7485 +6268 +7251 +7346 +8521 +5165 +8506 + +6788 +10715 +3520 +6591 +5738 +7419 + +37041 +22858 + +18343 +19902 +15427 + +13379 +7285 +11836 +9418 +9597 + +2796 +3345 +2704 +5395 +5386 +2687 +4133 +1749 +5117 +3822 +4244 +6093 +3108 +2015 +1322 + +3640 +6611 +5160 +6176 +4105 +3796 +4651 +6634 +3804 +3308 +3206 +6686 +3122 + +15465 +12326 +11646 +3744 +2857 + +2724 +3037 +3333 +6247 +9610 +7087 +2883 +6291 +6549 + +2860 +4870 +8726 +4865 +7283 +6364 +4892 +8653 +1937 +1356 + +6900 +4695 +4167 +6336 +1515 +3047 +6735 +4487 +1255 +3833 +3786 +1489 +5117 + +8133 +11386 +1756 +2859 +7861 +4284 +9113 + +2766 +8069 +1212 +2325 +6421 +7231 +6566 +1833 +2677 +3622 +6814 + +7498 +5282 +7407 +3241 +5596 +3862 +7268 + +12142 +3155 +7969 +6330 +10030 + +2534 +2657 +3129 +1604 +5325 +6252 +1007 +4982 +4123 +6270 +2391 + +9554 +15638 +14218 +15314 + +17850 + +4336 +7216 +8068 +2602 +7176 +5411 +1504 +7965 +5582 + +1910 +10293 +9366 +1653 +7607 +1238 +6089 +9832 + +8438 +18781 +8544 +14156 + +3472 +8118 +2455 +1789 +7535 +6667 +2003 +1025 +7340 + +2807 +9390 +13476 +10938 +2272 +5114 + +3311 +13209 + +10615 +15963 +6233 +9368 +13767 + +11712 +3170 +13964 + +3689 +9486 +9551 +3456 +4882 +11211 +1600 + +6760 +5563 +3589 +8736 +7398 +4388 + +9518 +4642 +3473 +11134 +1020 +3983 +1012 + +3776 +1573 +6476 +6958 +2257 +2912 +2577 +3201 +5425 +2764 +6006 +4068 +3984 + +3516 + +12606 +33693 + +22285 +30183 + +6732 +2689 +7685 +5674 +1023 +2447 +5675 +6507 +7257 +4059 +2773 + +14742 +13724 +5856 + +19020 +15808 +15831 + +6871 +5101 +5123 +7918 +1663 +4364 +5111 +6205 +6680 + +5241 +1029 +5194 +2693 +7420 +4095 +3765 +3433 +1752 +1822 + +4311 +10029 +9151 +9518 +2511 +2363 +6980 + +6760 +4212 +21929 + +5789 +2855 +7378 +1525 +3127 +6001 +8351 +8353 +4445 +2987 + +5246 +2746 +1650 +5781 +5816 +1068 +4261 +4453 +6656 +1395 +2589 +4375 +4263 + +2133 +10539 +2325 +2094 +9071 +4830 +5758 +2060 + +2173 +6292 +5585 +2040 +3758 +2941 +4877 +3816 +6376 +1493 +4425 +3327 +3551 + +2469 +3948 +6275 +3614 +2736 +6400 +5997 +6010 +4231 +4716 +5492 +2055 +1836 + +7704 +6489 +3032 +8583 +7929 +8709 +7837 +5110 +3939 +4258 + +3360 +6562 +19776 + +12387 +9654 +1246 +12376 +12271 +6105 + +2945 +14862 +15087 +15649 +2445 + +3191 +4141 +4266 +3335 +2222 +3679 +5209 +5109 +6873 +6313 +2765 +2442 +2133 + +10886 +3410 +16022 +19192 + +14993 +2080 +9131 +19401 + +1222 +4856 +5484 +4898 +3546 +3996 +1054 +6444 +2077 +1460 +4349 +2253 +5826 +6257 + +7221 +11757 +1038 +4768 +12836 +13339 + +4975 +17027 + +2688 +1733 +3844 +6205 +3089 +1343 +7323 +2613 +1223 +4277 +5551 +3968 + +3475 +4760 +6351 +7360 +2946 +1337 +3434 +2485 +6407 +3266 +3517 +2125 + +21512 +23024 + +27755 +1947 + +6307 +1957 +6982 +1516 +1671 +1054 +4311 +4235 +6952 +8129 + +6734 +11365 +9035 +9922 +7310 +4799 +5883 + +59886 + +1919 +10200 +5393 +6601 +4924 +10451 +10218 +3175 + +2360 +4470 +1823 +3699 +4974 +3365 +2002 +5251 +1188 +3192 +2328 +2461 +1931 +1506 +2544 + +6131 +4712 +4994 +5450 +3023 +2002 +6108 +1591 +1011 +1689 +3003 +3970 +3613 + +7374 +2176 +5878 +4112 +1213 +5819 +3944 +3250 +5839 +1207 +4641 + +4375 +2510 +1107 +1717 +4333 +5631 +2499 +4002 +3822 +3618 +5259 +7133 + +6307 +6702 +1754 +4893 +4003 +5101 +3275 +3579 +2235 +6823 + +7388 +6708 +2218 +2220 +5287 +8692 +8143 +5692 +4287 +7770 + +5881 +1741 +7408 +2466 +14095 + +9268 +2524 +2958 +15427 +14742 + +3955 +7993 +6342 +2637 +5825 +3660 +5537 +1832 + +1022 +3769 +2113 +5734 +4382 +5338 +4904 +3631 +1073 +4992 +4134 +1773 +2645 +4100 +3882 + +31354 + +22767 +13308 +3424 + +18428 +9719 + +13154 +13267 +1035 +10201 +3948 + +3104 +2047 +2790 +6051 +3733 +4667 +3701 +2668 +2197 +3221 +3145 +1999 +3303 + +1703 +1792 +4827 +5038 +1712 +2516 +4798 +1464 +3073 +4214 +4870 +5705 +4507 +5712 + +2151 +4888 +2967 +1081 +1474 +2949 +1942 +4762 +1432 +5156 +2345 +5225 +3496 +6123 + +2205 +2399 +5266 +8514 +8150 +7435 +4416 +5244 +2903 +7406 + +4278 +3403 +6713 +8407 +3593 +7880 +8196 +7305 +1762 + +4341 +19333 +3617 + +7586 + +16168 +1909 +8778 +4452 +4148 + +3790 +3233 +2400 +6936 +1376 +4576 +6698 +1305 +4930 +5510 +2721 +1772 +2293 + +5791 +2163 +1948 +3948 +8564 +6399 +8272 +9733 + +5423 +6215 +1459 +6879 +4283 +4006 +5135 +5086 +3024 +2603 +3646 +3998 +2984 + +4991 +8870 +9477 +6827 +4847 +8241 +6970 +6532 + +3660 +36765 + +2699 +7895 +2763 +2460 +2477 +4390 +1370 +5744 +7657 + +3183 +2115 +2175 +2887 +2336 +8459 +8135 +1868 +1095 +6213 + +5677 +2990 +5916 +6344 +5605 +2072 +2173 +3704 +2888 +1999 +7661 + +24731 +13470 +5599 + +8873 +6995 +5302 +12016 +8988 +4674 +10185 + +5528 +19366 +18649 +9187 + +7428 +3617 +5583 +6033 +8532 +3632 +2565 + +6725 +1708 +1735 +1662 +4790 +3215 +4378 +2562 +3136 +2268 +3323 +6101 +3908 + +67860 + +3912 +2698 +2610 +1883 +7163 +7834 +8215 +4361 +4631 +6559 + +61469 + +1752 +3571 +5372 +1210 +2232 +4724 +2075 +4374 +6962 +1331 +3080 + +4392 +3755 +8553 +10430 +2077 +6502 +9329 +8373 + +4642 +6832 +6307 +5022 +4373 +5532 +4745 +1098 +6005 +4653 +4683 +6255 +6875 + +7024 +1051 +5664 +1399 +7333 +4725 +3375 +3832 +7361 +6068 +1187 +1447 + +19585 +7175 +19834 +13102 + +6423 +10860 +6839 + +6385 +7387 +13727 +13764 +13174 + +3453 +1935 +6047 +2440 +6454 +2789 +5995 +5238 +2206 +5418 +2905 +5424 +6725 + +20427 +11408 +21179 + +1648 +6294 +5757 +6484 +6851 +6987 +4177 +4898 +6845 +7343 +1573 + +23105 + +4696 +5155 +3429 +2107 +6849 +1619 +2146 +2232 +1080 +8086 +7818 + +4525 +3467 +1486 +8013 +7366 +3654 +5303 +7754 +6469 +1468 +3874 + +8007 +5589 +6424 +9322 +10417 +1508 +5900 + +3644 +2169 +8705 +1837 +3247 +8079 +7704 +2387 +2802 +4142 + +5554 +4692 +1368 +2623 +4146 +3634 +3354 +5121 +2171 +3418 +7129 +1334 + +18870 +23687 + +13467 +5594 +13229 +2978 +7542 + +2239 +7363 +3465 +7284 +2900 +7929 +5295 +4752 +2225 + +4445 +15568 + +3892 +2012 +2469 +1666 +1613 +3789 +5048 +1514 +2444 +3556 +3011 +5467 +5248 +4722 +2803 + +4793 +3118 +1831 +2977 +3936 +1036 +4325 +4205 +5869 +4957 +5223 +4290 +4719 +2397 +4679 + +4298 +5696 +5284 +1761 +6972 +1749 +1766 +3024 +2173 +6806 +6209 + +4805 +2409 +5913 +1863 +6111 +3958 +1514 +1970 +6399 +1839 +5697 +3174 +6203 + +12825 +8917 +10603 +6987 +8314 + +16810 +10340 +21902 + +1836 +3878 +1856 +2099 +6527 +4670 +2388 +1364 +2119 +5725 +2976 + +2368 +15063 +12997 +6731 +3508 + +3583 +4242 +5197 +2541 +3058 +5540 +4464 +4867 +3424 +6194 +2071 +1310 +5976 +5290 + +4262 +5256 +1625 +3579 +2688 +2816 +5619 +5282 +2163 +1264 +1820 +2748 +1064 +3239 +3082 + +8888 +17024 +18873 +12576 + +5571 +2530 +4707 +6564 +2637 +6947 +4981 +1116 +3747 +1187 +3968 +6569 +6926 + +5158 +4884 +2078 +1283 +6676 +4477 +7153 +3696 +1282 +3218 +6716 +2714 + +68708 + +12439 +12815 +12165 +6292 +8568 +7503 + +18845 +9399 + +3205 +33907 + +2754 +2530 +2082 +2114 +5490 +2469 +5103 +5656 +1633 +5631 +1633 +5003 +5194 +3584 +2830 + +4197 +11261 +3154 +5946 +7624 +4258 + +1338 + +4227 +8355 +5986 +8348 +4869 +6318 +6432 +7363 +6661 + +9115 +3231 + +9797 +4164 +16220 + +4412 +2616 +1705 +3033 +5695 +4241 +4252 +2810 +4176 +2554 +6251 +1751 +5832 +5548 + +3098 +4538 +5763 +4913 +3322 +5956 +1910 +4210 +3629 +5531 +1243 +5258 +4642 +5572 +3838 + +10520 +2932 +18639 +7802 + +15433 +3635 + +4777 +5260 +1283 +7917 +5860 +1376 +8001 +1209 +6245 +5939 +4721 + +6893 +4349 +1011 +1314 +5878 +3129 +1410 +4377 +2089 +3518 +3560 +1205 +6452 + +16914 +17575 +8660 +17142 + +15028 +10221 +16158 + +11777 +10449 +13633 +19094 + +10289 +9390 +3685 +3979 +12643 + +15858 +24129 +9740 + +2707 +1840 +3010 +1744 +1509 +5039 +4158 +2900 +4999 +3619 +5309 +4386 +2105 +2919 +2327 + +2358 +1502 +6302 +1270 +3358 +2033 +5857 +1125 +6738 +5707 +3960 +6751 +2829 + +2690 +2401 +4685 +1891 +4701 +4503 +5740 +6441 +1119 +4211 +2072 +1476 +1779 +1943 + +1490 +12834 +3680 +13513 +1055 +9731 + +5322 +13458 +2941 +1758 +11817 +4550 + +3688 +4536 +5079 +4031 +5642 +5920 +5061 +4114 +3118 +3316 +1980 +5607 +2845 + +4372 +7991 +11604 +6661 +12052 +1241 + +4013 +4554 +5176 +4386 +6064 +1319 +4562 +1902 +4010 +3954 +1265 +4361 +2068 +3759 +4652 + +11866 + +4305 +1270 +2941 +6582 +3164 +3522 +4611 +4191 +3659 +7416 +4855 + +5179 +8236 +3392 +11505 +8487 +4344 + +7032 +27996 + +5322 +4909 +4858 +1281 +5937 +1289 +4176 +5993 +2841 +2188 +4192 +3398 +1800 +2678 + +5789 +13043 +4951 + +4119 +10014 +8815 +6749 +4545 +7692 +8436 +6740 + +10382 +8802 +7279 +4950 +1653 +3537 +10285 +7896 + +9975 + +3544 +5188 +5111 +2576 +7568 +7371 +6930 +4818 +7435 +6810 +2847 + +52788 + +2951 +8272 +6521 +5428 +6863 +3722 +6443 +1114 +7114 +2776 + +4386 +1913 +7477 +2665 +7932 +4653 +5426 +4484 +1108 + +3541 +3719 +3868 +1077 +4637 +2936 +3503 +5201 +5315 +5940 +2278 +6496 +1172 +4755 + +6439 +5144 +6491 +1234 +1459 +1968 +5797 +4909 +5923 +6534 +5268 +2147 +5632 + +2993 +3284 +4366 +5384 +4598 +1051 +3969 +2961 +7025 +2727 +4233 +3326 + +9727 +15517 +19290 + +17096 +1375 +14129 +10456 + +4103 +6099 +2887 +2589 +2957 +6664 +6948 +5126 +2427 +3269 +2868 +6296 +4641 + +1935 +5903 +3249 +1842 +4289 +5319 +2667 +4309 +2668 +3080 +3400 +3762 +2166 +2408 + +7866 +7422 +14288 +15942 +6371 + +1693 +2509 +6586 +4294 +7542 +1271 +8072 +4193 +8047 + +1925 +1564 +6018 +6894 +3300 +4040 +4154 +1720 +5159 +5001 +1605 +6080 +2792 + +16335 +11723 +7586 +12891 +13423 + +12011 +11646 +5317 +2769 +9679 + +6924 +1571 +3645 +4124 +5594 +7185 +7705 +2532 +7397 +5459 +1037 + +3948 +4286 +6395 +2645 +1835 +4764 +2649 +3403 +2704 +4039 +4581 +5278 +4128 +6174 + +5567 +8309 +4782 +5394 +4052 +5453 +7241 + +8673 +2968 +6481 +3887 +8279 +7800 +2025 +4775 +4627 + +6856 +1361 +6648 +7563 +4239 +10679 +8050 +8027 + +4905 +11553 +2902 +12065 +5974 +9578 +9837 + +6128 +6201 +2999 +6195 +1121 +2830 +4668 +5007 +1825 +2830 +5287 +5471 +5759 +1805 + +6515 +17925 +23344 + +4610 +2265 +7019 +2395 +3396 +5131 +7067 +5803 +1994 +6492 +3618 + +7951 +1762 +7521 +4837 +1589 +6260 +5765 +7442 +6185 +2695 +5675 + +4104 +6509 +5143 +2862 +5655 +2104 +5772 +6257 +2689 +3244 +3501 +2054 + +3967 +1326 +5906 +2740 +3487 +6586 +2908 + +43279 + +4935 +6761 +6021 +4857 +3040 +1491 +3820 +2741 +7058 +3114 +5775 + +6458 +8250 +3691 +7478 +4003 +6917 +8033 +1181 +6882 +6533 + +12020 +5725 +24247 + +6550 +1033 +1841 +5367 +1621 +6554 +5355 +7437 +8079 +5876 + +9079 +12200 +16431 +8582 +15548 + +7910 +16510 +25149 + +2569 +3570 +6639 +1706 +7204 +4964 +3314 +1862 +4344 +3529 +7688 + +9213 +15614 +12172 +15703 +6499 + +4927 +2418 +4565 +2409 +5355 +1464 +4788 +2040 + +1499 +5180 +2638 +5857 +2693 +5068 +3382 +1202 +5745 +3817 +1174 +3182 +3011 +5823 +4302 + +1992 +1060 +1356 +5702 +2700 +2129 +4364 +5380 +2317 +2392 +1269 +6268 +3462 +5392 + +4601 +1395 +8724 +2017 +11000 +2414 +9399 + +5998 +4595 +1327 +9386 +6206 +2712 +9617 +5234 +7096 + +5436 +6415 +4210 +1032 +1825 +4408 +4903 +3803 +1197 +2849 +4106 +5611 +4553 + +3572 +6127 +6035 +6950 +4353 +1660 +2135 +2866 +1322 +4847 + +2181 +4407 +2006 +5437 + +3560 +4717 +5998 +6944 +2180 +6922 +8628 +2761 +3524 +2473 + +6215 +2369 +5907 +6959 +7105 +4982 +5255 +2650 +1834 +7016 +3072 + +1564 +6445 +6037 +6545 +4622 +6301 +1712 +2949 +3608 +3965 +2602 +5065 +6050 + +12326 +10342 +12805 +11947 +2641 +10687 + +15426 + +19377 +13829 +6477 +11837 + +7159 +7868 +6373 +10135 +10731 +6850 +5819 + +6938 +25628 +22954 + +5570 +5782 +8571 +7353 +2189 +6056 +2774 +7061 +6279 +1923 + +1200 +5306 +6067 +2575 +4613 +1321 +1525 +1545 +1059 +5337 +1920 +1367 + +9230 +8121 +5933 +11082 +5561 + +6447 +3340 +6950 +2194 +3685 +5311 +3610 +4332 +6755 +4780 +1164 +4978 +2476 + +3111 +6078 +2022 +7748 +5569 +2895 +4911 +7478 +4002 + +2414 +3673 +3897 +11893 +4984 +3471 + +6240 +6211 +5245 +15319 +6704 diff --git a/src/bin/01_1.rs b/src/bin/01_1.rs new file mode 100644 index 0000000..c2e0d2e --- /dev/null +++ b/src/bin/01_1.rs @@ -0,0 +1,30 @@ +#![feature(slice_group_by)] + +use itertools::Itertools; +use itertools::max; +use std::fs; +use anyhow::Result; + + +fn main() -> Result<()> { + let input = fs::read_to_string("input/01.txt")?; + + let groups = input + .split("\n").collect::>() + .into_iter() + .group_by(|ell| *ell != ""); + + let elves = groups + .into_iter() + .filter(|(key, _)| *key) + .map(|(_, elf)| elf + .into_iter() + .map(|val| val.parse::().unwrap()) + .fold(0, |acc, val| acc + val) + ); + + let highest = max(elves); + println!("{:?}", highest); + + return Ok(()); +} diff --git a/src/bin/01_2.rs b/src/bin/01_2.rs new file mode 100644 index 0000000..d1158de --- /dev/null +++ b/src/bin/01_2.rs @@ -0,0 +1,35 @@ +#![feature(slice_group_by)] + +use itertools::Itertools; +use itertools::sorted; +use std::fs; +use anyhow::Result; + + +fn main() -> Result<()> { + let input = fs::read_to_string("input/01.txt")?; + + let groups = input + .split("\n").collect::>() + .into_iter() + .group_by(|ell| *ell != ""); + + let elves: Vec = groups + .into_iter() + .filter(|(key, _)| *key) + .map(|(_, elf)| elf + .into_iter() + .map(|val| val.parse::().unwrap()) + .sum() + ).collect(); + + let highest = sorted(elves); + let sum: i32 = highest + .into_iter() + .rev() + .take(3) + .sum(); + println!("{:?}", sum); + + return Ok(()); +}