commit f05a2a1a4d0194e8b855a68d46925b7f4ddbbde6 Author: Louis Vallat Date: Thu Dec 1 10:43:08 2022 +0100 feat: day1 Signed-off-by: Louis Vallat diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a9d37c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target +Cargo.lock diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..1a2295c --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,11 @@ +default: + image: rust + +stages: + - build + +day-1: + stage: build + script: + - cd day1; cargo run --release ./input + diff --git a/day1/Cargo.toml b/day1/Cargo.toml new file mode 100644 index 0000000..a3c4e52 --- /dev/null +++ b/day1/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day1" +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/day1/input b/day1/input new file mode 100644 index 0000000..24abd2e --- /dev/null +++ b/day1/input @@ -0,0 +1,2237 @@ +17998 +7761 + +5628 +1490 +4416 +2606 +2828 +4615 +3206 +7218 +4793 +5199 +2129 + +6451 +5761 +5083 +4234 +3772 +6652 +6856 +4224 +3168 +2459 +3736 +3020 +1545 + +3562 +6789 +4611 +1955 +5887 +7005 +5044 +6414 +1524 +3016 +3960 +1040 + +5057 +6712 +2704 +7012 +5828 +4114 +3850 +5661 +2520 +4217 +2117 +1732 + +10514 + +25104 +24972 +13901 + +28648 +33075 + +5272 +3309 +1538 +4691 +5707 +3432 +5693 +2276 +1805 +3794 +3362 +1104 +1445 +1771 +4570 + +56986 + +16245 +3073 +9516 +7686 +4572 + +2491 +4375 +6060 +4967 +2406 +5675 +2058 +3965 +1925 +1386 +4487 +2947 +2232 + +7244 +3155 +1436 +11024 +8644 +10687 + +11558 +1875 +11262 +13875 +13398 +1099 + +5313 +2948 +2501 +6936 +3538 +5185 +4244 +6732 +3687 +2631 +4751 +5400 +2762 + +25777 +4203 + +6932 +3584 +2576 +1255 +9393 +3318 +3123 +7804 + +2923 +4282 +6520 +8024 +4720 +11614 +7675 + +9578 +28905 + +7064 +3114 +1084 +3705 +1274 +9620 +6372 +2437 + +11263 +1363 +16201 +10139 +2800 + +2552 +25633 + +18808 +17513 +13507 + +1268 +6507 +5040 +4038 +2720 +5182 +5391 +5364 +1649 +2573 +1588 + +3431 +5596 +4712 +2528 +5819 +2990 +1903 +1543 +5282 +2264 +4354 +1642 +5727 + +3132 +6207 +1830 +7901 +2391 +1833 +7618 +7434 +7647 +3228 +3616 + +35533 + +2996 +11761 +12345 +3497 +9161 + +13665 +16927 +8077 +12827 + +10616 +2069 +2017 +9954 +6511 +7164 +1726 + +4864 +5356 +7492 +6838 +4996 +3581 +6995 +1675 +6228 +4443 +3337 + +24945 +35554 + +7341 +5417 +8143 +6570 +1247 +3575 +8900 +2852 + +5331 +2936 +3786 +4775 +4813 +5521 +3054 +5516 +7575 +1462 +7589 + +7847 +3392 +9324 +10042 +9525 +1549 +2937 +10243 + +32520 +7227 + +4654 +5795 +4072 +6139 +7918 +4684 +3777 +2814 +8423 + +61078 + +4697 +2225 +5930 +6405 +1086 +4380 +5282 +3581 +1260 +4341 +3917 +4853 +1317 +3867 + +7569 +1393 +7584 +2276 +2488 +7487 +3431 +2391 +7861 +1262 +1183 + +2950 +3411 +1990 +2602 +4339 +3807 +6007 +6229 +5531 +2982 +6462 +5189 +6302 +2552 + +25907 +26002 +2739 + +9365 +15899 +4030 +1658 +9012 + +5212 +9491 +8976 +7791 +10025 +10562 +5194 +6835 + +7272 +6873 +4851 +2388 +1703 +6162 +7320 +3773 +1208 +4285 +3469 +1116 + +6860 +2596 +4724 +6130 +6914 +3782 +8998 +2918 +7637 + +5894 +3334 +5981 +3871 +3753 +1134 +5370 +2034 +2912 +7223 +6644 +3705 + +6807 +6539 +6122 +4686 +7317 +6842 +1197 +4922 +3669 +2664 +7510 + +12485 +13975 +13484 +11724 + +5987 +5497 +3662 +6144 +6094 +7833 +5543 +4452 + +1003 +5469 +5894 +1486 +4418 +1969 +2509 +3414 +3625 +4010 +3413 +1592 +3313 +1465 +4747 + +7008 +3208 +12837 + +8199 +6041 +1498 +9319 +10292 + +1241 +4805 +5890 +7312 +6532 +4471 +7718 + +13465 +1639 +1665 +10581 +2712 + +1497 +3588 +4080 +5793 +1311 +6139 +2014 +2772 +4764 +3288 +4533 +4451 +3239 +2720 + +2660 +3173 +7052 +7182 +4577 +3043 +6094 +3949 +5209 +1405 +5353 + +6758 +4101 +3349 +1745 +2583 +4242 +1181 +1975 +5230 +3624 +1869 +5579 +4131 + +1023 +6068 +3231 +5803 +1601 +1347 +4905 +5247 +4351 +2828 +2623 +4458 +5961 +3157 +1727 + +5860 +3074 +1496 +1738 +6000 +5254 +4777 +5030 +4669 +3906 +3628 +6020 +2038 +2314 +4696 + +8390 +3660 +3437 +7819 +5326 +7072 +4897 +2400 +3750 +7632 + +6217 +3627 +4678 +4326 +7245 +9537 +11023 + +18710 +17134 +12605 +13113 + +1097 +3971 +1496 +1779 +1473 +5579 +2001 +3879 +4370 +4961 +1185 +2349 +5880 +2241 +2062 + +6456 +1596 +1630 +4299 +5637 +3219 +1098 +5545 +4726 +1059 +3301 +3008 +2539 +2993 + +2831 +3437 +4552 +7853 +1611 +3869 +2125 +6249 +7708 +4146 +3032 + +3143 +8453 +12692 +7237 +9487 +12677 + +5314 +2578 +3386 +5782 +8142 +6667 +9128 +4875 +7279 + +36180 + +32105 +26198 + +2866 +5127 +6614 +6754 +1228 +4187 +3949 +1489 +2795 +2967 +5894 +4939 + +8271 +6294 +5940 +7992 +1639 +5806 +6221 +3394 +5916 +8808 + +15779 +8903 +19615 +14420 + +7624 +2808 +3707 +4083 +1098 +1457 +7940 +3233 +7274 +1281 +7540 + +13773 +5128 +4524 +12503 +9127 +4966 + +10326 +3371 +2691 +5935 +1708 +10453 +3603 +3693 + +2357 +5560 +2776 +1310 +6820 +1308 +1553 +1325 +3059 +1072 +5793 +3453 +2439 + +2214 +1405 +8728 +7644 +6761 +9531 +4373 + +7321 +9249 +9581 +8570 +1547 +2693 + +34569 + +3456 +6648 +6999 +2536 +8626 +4551 +7325 +4425 +6223 +2870 + +3420 +4022 +8524 +11447 +4207 + +4748 +8782 +7397 +1070 +7248 +4800 +3744 +1689 +1569 +1791 + +5749 +2554 +5195 +3327 +4545 +1247 +1358 +2490 +3462 +1304 +2779 +5408 +2053 +2257 +1482 + +2797 +3543 +2062 +5969 +1947 +2651 +1869 +3940 +5795 +2429 +2192 +3482 +2124 +5142 +3846 + +1824 +4887 +6473 +2807 +4552 +5247 +2337 +6489 +2629 +4019 +3966 +4706 + +4586 +4473 +5264 +6318 +5034 +7968 +5207 +4565 +4480 +4182 +5200 + +25789 +14421 + +2031 +4476 +5632 +2280 +5768 +1497 +1790 +5483 +2238 +3311 +5948 +2183 +1268 +4112 +4662 + +4591 +15992 +14465 +1019 +6359 + +2607 +1142 +3113 +6932 +7322 +2790 +1748 +10062 + +1698 +3132 +4331 +4897 +1314 +1890 +5029 +4832 +1977 +4897 +5565 +5174 +3486 +3701 +5891 + +3968 +4464 +5827 +3207 +3137 +1656 +7822 +7031 +6324 +1383 +7370 + +3447 +7368 +3917 +2594 +3260 +3625 +7061 +3952 +8071 +5817 +4487 + +2044 +1966 +4663 +4024 +2801 +7345 +3110 +2600 +1476 +5577 +5376 + +2900 +3381 +1471 +3336 +5977 +7444 +1922 +6280 +4567 +5133 +2286 +5709 + +1724 +6255 +12013 +6040 +6139 +10413 + +5297 +6572 +3549 +5947 +4278 +1205 +4145 +5719 +4386 +6211 +4667 +4619 +5232 + +8533 +7320 +10869 +9241 +9904 +2350 +7989 + +4987 +8610 +3379 +3183 +5180 +2766 +5376 +7218 +8347 +1560 + +3041 +2227 +5006 +6226 +3810 +6564 +2379 +6009 +1502 +6050 +4726 +1067 +3479 + +5661 +2282 +1119 +5999 +1974 +2413 +5945 +6684 +3405 +4052 +3620 +4260 +3271 + +3854 + +5873 +3633 +3510 +7025 +1700 +2517 +6904 +4839 +5550 +2479 + +5797 +9048 +2793 +4570 +7651 +9982 + +6992 +20085 +23589 + +10445 +1035 +11663 +4210 +3968 +1951 +9878 + +3196 +5525 +3301 +2358 +2813 +4503 +4565 +2185 +4747 +4392 +5941 +1054 +4433 +2231 +3437 + +3204 +1936 +6501 +3121 +7088 +2978 +2397 +7183 +1532 +2540 +6450 +5918 + +16099 + +3769 +6180 +6821 +2120 +7341 +3334 +4377 +2600 +6645 + +4761 +17688 +18322 +3258 + +4986 +3809 +6859 +7686 +2395 +2867 +5312 +3437 +2755 +2792 +4808 + +6817 +3244 +4661 +6026 +5924 +1997 +6956 +5076 +5972 +1475 +4832 +6325 +1208 + +5495 +4785 +4386 +7183 +6366 +8797 +8611 +3144 +8750 + +5268 +22215 +8788 + +2098 +6983 +8443 +8853 +6901 +6700 +3791 +9794 + +17836 +4117 +18986 +3522 + +8415 +11041 +22269 + +3806 +4713 +5924 +6520 +1689 +5491 +3428 +5077 +5203 +2281 +5943 +3981 +4935 + +3781 +6911 +3634 +4014 +4487 +1848 +1581 +6414 +6159 +3378 +2172 +5779 +1496 + +5630 +5806 +11173 +12715 +3749 +10308 + +2004 +2301 +5493 +4883 +7959 + +56853 + +3776 +6337 +5589 +4861 +6367 +2196 +8706 +8522 +6434 + +2635 +1649 +2441 +1415 +5412 +1752 +1209 +3147 +3714 +4133 +2105 +3355 +2094 +4566 +3104 + +1740 +7754 +6207 +7135 +6162 +6373 +6412 +5305 +3162 +4212 +5574 + +8757 +5847 +5378 +7051 +2413 +2400 +8644 +2769 +2801 +3994 + +3379 +3797 +8624 +2583 +6638 +4951 +6613 +6927 +3461 + +8688 +10537 +7633 +8765 +4039 +5851 + +10262 +4282 +5123 +6845 +3247 +6596 +8248 +6166 + +3495 +7378 +7226 +6307 +4573 +7312 +6673 +3311 +6361 +8165 + +11763 +10039 +2199 +4523 +11320 +2285 +3273 + +5216 +3875 +1224 +7137 +6141 +3555 +6474 +4145 +6684 +7411 +2277 +1206 + +7729 +2649 +3401 +2362 +8376 +3798 +8786 +8353 +5649 +3598 + +6302 +4544 +8908 +16983 + +3111 +3459 +4527 +1658 +3383 +2427 +3080 +6411 +5283 +2756 +1635 +2967 +5700 +2754 + +7795 +1055 +6226 +9585 +3492 +4774 +9585 +2737 +4999 + +3954 +34109 + +6101 +2437 +3685 +4199 +4141 +3032 +6759 +6097 +6005 +1143 +4895 +6743 + +6728 +4526 +6352 +6009 +5599 +7226 +7720 +2413 +5292 +3967 +7949 + +5878 +3090 +6035 +2771 +5327 +3472 +5972 +2424 +2805 +2958 +1647 +4939 +4350 +2966 +1746 + +43782 + +17434 + +10390 +19366 +2872 +13959 + +1855 +2608 +3828 +6368 +6566 +2668 +1618 +4319 +5748 +5329 +2079 +3851 +3390 + +1063 +3790 +4931 +5663 +1643 +4802 +2313 +4556 +3226 +1350 +2541 +3254 +2831 +3608 +5620 + +1986 +2266 +3694 +1616 +2591 +2796 +2632 +2753 +4876 +3771 +3037 +4230 +4758 +3689 + +3046 +1124 +1919 +5808 +6592 +12099 +3006 + +7730 +6684 +5182 +6952 +5491 +3743 +3441 +6272 +3836 +7060 + +4704 +7848 +3439 +6002 +1988 +2849 +7831 +4772 +6457 +5839 +1164 + +1037 +4311 +5686 +11750 +12792 +2073 + +7000 +5169 +1434 +5338 +3407 +2781 +5681 +1737 +1820 +1977 + +28120 +34293 + +4333 +5592 +5595 +4486 +4130 +1843 +5333 +4428 +2732 +3915 +2489 +4583 +2980 +3777 +1924 + +9944 +1732 +9361 +9725 +4422 +1430 +8790 +7033 + +6593 +17982 +6262 +4186 + +2244 +6909 +3116 +1377 +4651 +2330 +3557 +1335 +6292 +2583 +1003 +4630 + +6874 +6457 +2368 +4244 +7837 +8385 +4225 +6132 +2000 +3278 + +1640 +8813 +1450 +4314 +6244 +6625 +8631 +4906 +5445 + +8167 +6023 +2394 +8080 +7244 +5757 +5131 +2968 +6253 + +5317 +4955 +1502 +4858 +6335 +2822 +6414 +4964 +1239 +5585 +2870 +1390 +3443 +5835 + +16643 +17478 +14966 +18257 + +1197 +7985 +6657 +5412 +5659 +7745 +2526 +2860 +3091 +1308 +7234 + +1265 +4489 +1845 +4754 +1820 +2405 +8366 +3157 +3409 +6019 + +5123 +7178 +4413 +7042 +3720 +9815 +2125 + +1562 +1713 +4145 +2010 +1198 +3603 +2037 +5751 +2704 +5145 +3957 +1518 +2727 +3631 + +2560 +5248 +3618 +4954 +4373 +3634 +3060 +4099 +1987 +1523 +3766 +5288 +6016 +6100 +3335 + +7168 +3969 +5720 +6880 +4418 +5207 +1952 +6590 +5821 +7483 +2247 + +5823 +3277 +1097 +5365 +5011 +4023 +2884 +1355 +5897 +2289 +1938 +4617 + +13491 +14397 +6773 +12961 + +4923 +6940 +6730 +6284 +9194 +4413 +4506 +8231 + +14458 +21321 +9376 + +5874 +9856 +2452 +8840 +9487 +4212 + +5808 +3000 +1518 +2918 +5982 +1174 +1852 +4666 +2185 +5512 +1985 +1033 +5255 +2987 + +59917 + +3178 +1989 +7090 +14100 + +7178 +8368 +8631 +2239 +3480 +11905 + +2110 +7822 +3685 +5278 +12993 +4605 + +4285 +3215 +8289 +8586 +6022 +4113 + +2506 +4846 +3627 +7766 +2270 +5410 +6651 +1747 +6588 +2745 +1644 + +6817 +2985 +12586 +8531 +10847 + +28805 +12412 + +4638 +4405 +5368 +1505 +1590 +2064 +6019 +5616 +6585 +3551 +6663 +2352 +3027 + +1539 +5984 +4600 +3812 +6041 +3347 +3068 +2728 +4187 +1518 +3361 +3254 +2014 +1221 + +10081 +4645 +7200 +2676 +2414 +9252 +6983 +8609 + +7282 +5270 +6267 +6574 +2111 +3647 +3372 +4330 +6727 +6126 +4648 +4301 + +1195 +4086 +1585 +7640 +7523 +7868 +1808 +2568 +7418 + +1165 +2644 +1622 +4172 +1764 +4987 +3948 +4784 +2037 +6892 +3603 +1303 +1431 + +11839 +18481 +14511 +14199 + +4981 +2842 +4225 +3875 +4677 +4200 +1250 +6053 +3295 +3906 +3559 +5555 +4061 +5217 +2461 + +2494 +7300 +5584 +5447 +4640 +1606 +4946 +6395 +2051 +3770 +1911 +1172 + +1893 +3297 +3796 +2443 +1281 +5749 +3004 +5946 +3159 +1817 +2410 +3121 +4681 +3902 +3822 + +17143 +28806 + +6419 +5937 +2928 +4352 +1167 +3065 +4412 +4174 +5363 +6639 + +1644 +7798 +3918 +13663 +8005 +2706 + +5972 +4312 +1101 +7683 +1864 +9147 +6275 +1091 +4705 + +4467 +6599 +4986 +2149 +4658 +6734 +6435 +3420 +1250 +7903 +3332 + +3822 +1657 +6440 +1715 +4745 +5644 +4194 +2628 +4445 +3862 +6407 +4124 +5645 +5647 + +9907 +15673 +10981 +8715 + +5165 +9566 +10302 +9463 +7354 +4953 +9936 +3418 + +1970 +3984 +2479 +2179 +8195 +1143 +6019 +6997 +7947 +4032 + +13151 +18259 +17163 +16038 + +3428 +3166 +4562 +4646 +1409 +4899 +6073 +2676 +3904 +3812 +4759 +1031 +4721 +4000 + +7913 +6923 +1866 +4059 + +4397 +3381 +2855 +2298 +5878 +5936 +1557 +4093 +2541 +3003 +5122 +4797 +1009 +1061 +6000 + +64983 + +7556 +4272 +10680 +6371 +1366 +10368 +6850 +4185 + +1475 +5068 +9461 +3928 +5800 +1518 +4635 +4355 + +5444 +9479 +10688 +9935 +2998 +6869 + +3939 +5553 +7708 +10959 +1146 +7359 +9252 + +5346 +7107 +4442 +3757 +2764 +7119 +3687 +2901 +6363 +2520 +3334 +2406 + +6676 +24658 +17509 + +5697 +2271 +1389 +4780 +1995 +6649 +1416 +3380 +1294 +2703 +2892 +6875 + +33668 +5537 + +3286 +6899 +6343 +6525 +4300 +5136 +5923 +3515 +4582 +4087 +5544 +5445 +6073 + +7639 +13167 +12720 +2061 +7872 +7245 + +49608 + +3356 +9248 +3725 +12066 +11380 +8888 + +48243 + +65156 + +11832 +5015 +4615 +1887 +3198 +6394 +7144 + +3119 +9555 +7129 +11257 +3248 +6137 +3827 + +7593 +19000 +13021 + +3370 +4726 +3248 +5255 +5342 +4610 +3196 +5626 +6664 +6266 +7477 +6842 + +7027 +4939 +4836 +2831 +4856 +10734 +6385 +9504 + +3103 +7618 +6901 +2292 +4648 +1971 + +11653 +2908 +17965 +6621 + +9505 +8435 +9650 +4220 +9735 +11858 + +4829 +4869 +2425 +9305 +9893 +1851 +3909 +3431 + +29854 + +2962 +18626 + +10966 +9129 +12203 +12026 +10735 +3064 + +7850 +6859 +4213 +7458 +4919 +7503 +3621 +3792 +8002 +6529 + +5132 +5646 +5893 +2495 +1550 +6538 +5822 +2421 +1229 +1508 +1014 +2112 +1766 + +3835 +2311 +4601 +3753 +5664 +4495 +4219 +4514 +1933 +3069 +4776 +1965 +2136 +2298 +2310 + +2161 +1963 +5635 +3770 +2541 +2349 +3743 +3828 +5408 +3004 +6073 +2460 +1981 +2409 +2110 + +5201 +3686 +2611 +4507 +4504 +1284 +3318 +6115 +1251 +3450 +5920 +4161 +5681 +6071 + +8874 +5512 +10369 +6186 +6516 +2477 +4878 +10026 + +4171 +1221 +1983 +1562 +2616 +6689 +3832 +5275 +6764 +7095 +3985 + +12828 +2639 +10883 +10054 +13688 diff --git a/day1/src/main.rs b/day1/src/main.rs new file mode 100644 index 0000000..1953887 --- /dev/null +++ b/day1/src/main.rs @@ -0,0 +1,41 @@ +use std::{fs, env}; + +fn read_input(path: &str) -> String { + return fs::read_to_string(path).expect("Cannot read file."); +} + +fn parse_input(s: &str) -> Vec> { + let mut ret = vec![]; + let mut buffer = vec![]; + for l in s.lines() { + if l.is_empty() { + ret.push(buffer.clone()); + buffer.clear(); + } else { + buffer.push(l.parse::().unwrap()) + } + } + return ret; +} + +fn sort_and_sum(input: &Vec>) -> Vec { + let mut summed = input.iter() + .map(|i| i.iter().sum()).collect::>(); + summed.sort(); + return summed; +} + +fn sum_of_last_n(sorted: &Vec, n: usize) -> i32 { + return sorted.iter().rev().take(n).sum(); +} + +fn main() { + let args: Vec = env::args().collect(); + for arg in args.iter().skip(1) { + println!("[{}]", &arg); + let vec_in = parse_input(&read_input(&arg)); + let sorted = sort_and_sum(&vec_in); + println!("\t[Part 1] => Answer is '{}'.", sum_of_last_n(&sorted, 1)); + println!("\t[Part 2] => Answer is '{}'.", sum_of_last_n(&sorted, 3)); + } +}