From 5055786d3db80e45a5c3f128f41866ea78865c45 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Thu, 1 Dec 2022 17:43:04 +0300 Subject: 2022, day1: done --- 2022/day1/input | 2244 +++++++++++++++++++++++++++++++++++++++++++ 2022/day1/part1/Cargo.toml | 9 + 2022/day1/part1/example | 14 + 2022/day1/part1/src/main.rs | 14 + 2022/day1/part2/Cargo.toml | 9 + 2022/day1/part2/example | 14 + 2022/day1/part2/src/main.rs | 21 + 7 files changed, 2325 insertions(+) create mode 100644 2022/day1/input create mode 100644 2022/day1/part1/Cargo.toml create mode 100644 2022/day1/part1/example create mode 100644 2022/day1/part1/src/main.rs create mode 100644 2022/day1/part2/Cargo.toml create mode 100644 2022/day1/part2/example create mode 100644 2022/day1/part2/src/main.rs (limited to '2022/day1') diff --git a/2022/day1/input b/2022/day1/input new file mode 100644 index 0000000..7be633e --- /dev/null +++ b/2022/day1/input @@ -0,0 +1,2244 @@ +8890 +13468 +5519 +4939 + +4580 +3529 +2917 +1329 +4004 +3553 +5457 +1907 +2515 +4055 +4626 +3776 +1982 +2967 + +10118 +2688 +4629 +3054 +3911 +6680 +6988 +6471 + +2836 +7494 +7963 +8528 +8732 +1743 +4794 +1685 +1406 +2575 + +7606 +11935 +4792 +7040 +8684 +1131 +3000 + +5799 +4398 +3837 +2155 +1889 +5560 +6684 +2045 +1194 +1280 +4009 +6944 +4754 + +3932 +10114 +9039 +10597 +6889 +5807 +8786 +5376 + +5666 +8741 +2305 +3914 +4521 +6449 +6590 +5933 +2765 + +1417 +3584 +3304 +5605 +6249 +3195 +5905 +5308 +3920 +2912 +4028 +2897 +4737 +6224 + +4498 +6139 +6716 +9309 +6210 +4120 +6244 +9313 +3275 + +5602 +4336 +5174 +4592 +3676 +6700 +1903 +4623 +5393 +3743 +2397 +5207 +3445 + +2219 +3393 +4442 +5142 +4466 +6851 +1877 +4005 +4792 +1370 + +11433 +10337 +11711 +4342 +6693 +2626 +6245 + +10039 +11192 +7335 +13284 +13507 + +1989 +5218 +4411 +4440 +3563 +1714 +3617 +3068 +1167 +1222 +3567 +3888 +2634 +2289 +3410 + +6518 +5391 +12964 +13103 +9070 +9803 + +22560 + +4229 +2789 +2219 +1940 +2848 +4053 +5849 +5518 +1088 +6297 +6603 + +2889 +3452 +4254 +3624 +4293 +1511 +5150 +2890 +5834 +6345 +6399 +1164 +3561 + +46632 + +19171 + +2510 +21303 +15390 + +54375 + +22699 +36690 + +2240 +3329 +3299 +5978 +4641 +3499 +3515 +4915 +4613 +2785 +4757 +5394 +2339 +2574 +5073 + +1321 +3132 +5429 +5664 +4451 +1397 +3284 +6077 +4117 +4818 +4430 +3163 +2432 +3894 + +6726 +2851 +9582 + +32549 + +17153 +18102 +11467 +20051 + +7167 +4819 +4283 +1900 +1524 +3228 +1712 +7107 +7453 +1137 +1927 +3876 + +14437 +7952 + +5253 +7062 +1107 +5023 +2353 +7335 +2819 +4925 +2439 +5186 +3602 +2016 + +4129 +26383 + +3665 +5169 +6365 +4399 +3518 +2176 +6185 +1150 +1490 +3818 +6223 +2104 +4006 +1142 + +1138 +11986 +5920 +6371 +7888 +8197 +10859 + +4338 +4292 +1523 +1044 +2498 +2514 +3160 +5049 +2113 +5867 +1916 +5458 +4686 +2012 +5455 + +15587 + +4040 +4077 +5272 +4914 +6755 +6297 +2240 +1925 +2940 +2346 +5688 +5501 + +1476 +4270 +1252 +4783 +3661 +5353 +4596 +5400 +5916 +1685 +3307 +3915 +5624 +1371 +2001 + +42703 + +1250 +2902 +6414 +6487 +6368 +1200 +2759 +3307 +5551 +1216 +4097 +3174 +3758 +2470 + +4997 +1199 +4598 +2443 +2931 +4287 +1606 +5156 +4750 +4117 +2487 +3399 +4283 +4991 +4441 + +1789 + +4379 +10889 +6020 +1102 +5043 +10061 +11276 + +7586 +13962 + +10039 +2029 + +2150 +2431 +3646 +4601 +5105 +4254 +5469 +5844 +6856 +4529 +3557 +3043 +4944 + +6797 +1605 +6624 +4966 +1452 +2260 +6281 +3273 +5754 +6576 +6326 +6391 +4892 + +9772 +16686 +1032 +14594 + +2978 +4118 +2292 +6107 +7428 +2954 +3516 +2464 +4726 +5438 +3292 +2812 + +6953 +7372 +5775 +7550 +8449 +7315 +2872 +2442 + +2581 +7301 +1256 +3467 +2348 +6254 +5231 +3225 +8275 + +3065 +4110 +5259 +8646 +4515 +7431 +7086 +3650 +2445 + +5714 +4659 +6401 +1647 +7071 +1302 +8529 +1570 +7288 + +49901 + +6687 +1879 +4661 +6048 +6920 +5048 +1537 +3786 +1634 +3274 +4277 +2712 +2647 + +5597 +4194 +4058 +5329 +2484 +3420 +2607 +2953 +2580 +1093 +2609 +2299 +4805 +3426 +4101 + +2833 +6833 +1455 +9758 +2307 +3045 +10558 + +3380 +4149 +8715 +5262 +7564 +9620 +3331 +6581 +7674 + +3389 +2996 +1250 +9915 +1731 +7254 +3784 +10198 + +4210 +6612 +6253 +6874 +5858 +4349 +4845 +1119 +4695 +4496 +6276 +4234 +6679 + +16077 +6437 +18269 +14173 + +19739 +5489 +3345 +5798 + +4150 +5984 +5293 +5741 +3166 +5279 +5244 +5215 +5010 +3367 +1828 +4310 +4335 +3973 + +2144 +12157 +9069 +1615 +1826 +7195 + +12924 +6962 +11433 +3150 +7863 +7387 + +3113 +3604 +7814 +10587 +3098 +10913 + +4513 +9048 +10027 +3587 +7837 +3906 +2299 + +4370 +6152 +5473 +5866 +5358 +4265 +4487 +6664 +2347 +6075 +1481 +4074 +1962 + +7409 +7332 +11378 +7740 +8090 +3036 +1310 + +8351 +6202 +1420 +9306 +7410 +11169 +9201 + +6951 +2037 +8682 +5075 +9709 +4678 +8347 + +10537 +13081 +5447 +8707 +11933 + +10454 +2543 +10319 +8133 +2072 +9299 +1929 + +7770 +4904 +8452 +8625 +7675 +4126 +1015 +4921 +8517 +2709 + +10877 +7192 +9475 +4555 +5625 +5261 +5756 + +6150 +9451 +11426 +11464 +6334 +10003 +8686 + +1959 +1711 +5018 +4235 +4920 +4257 +2511 +2572 +1347 +1871 +2102 +4203 +6334 + +12058 +8690 +1875 +7697 +12351 +7669 + +32887 + +31015 + +6024 +2966 +3311 +7248 +6280 +4727 +6071 +6771 +1599 +1958 +7649 + +9066 +13179 +1857 +12410 +1404 +11676 + +6262 +7283 +4418 +1207 +7099 +2798 +6994 +5267 +7810 +6521 + +7144 +3828 +5528 +4676 +2311 +6429 +7064 +6601 +2846 +1611 +3188 + +4151 +6232 +5706 +7003 +3470 +8349 +8189 +4137 + +3055 +6091 +2008 +5977 +1909 +1192 +2149 +2983 +1219 +1025 +1537 +2635 +5461 +5570 +5620 + +25514 + +19363 +16402 + +6908 +4670 +3407 +4541 +5027 +5640 +1008 +5737 +2336 +2994 +3908 + +2788 +5117 +18397 +5362 + +2285 +1597 +1556 +1505 +1317 +1136 +3387 +4936 +6798 +7103 +5537 + +7045 +4354 +6071 +6734 +11077 +5863 +7177 + +5625 +3990 +6473 +3191 +1023 +3673 +2520 +5998 +2726 +5421 +1907 +7129 + +1302 +1703 +6858 +1329 +1933 +3438 +4088 +7955 + +8593 + +6686 +3483 +5829 +2240 +6810 +2964 +5400 +3826 +4753 +5525 +5395 +5127 +6010 + +9254 +37116 + +1487 +18037 +9573 +14918 + +6570 +3119 +1689 +3785 +4436 +6237 +4394 +4042 +1242 +7143 +1621 +5211 + +3851 +1651 +2177 +5699 +4866 +5048 +5174 +1271 +3971 +2695 +1051 +1670 +1372 +3959 +1264 + +8039 +1858 +9989 +8870 +7618 +5662 + +1059 +8999 +2214 +5310 +8052 +5807 +1963 +4282 +8489 + +1444 +2736 +3879 +2437 +3539 +3657 +2351 +4513 +4299 +4166 +5665 +4164 +3622 +1907 + +3638 +4328 +4562 +3285 +3200 +5909 +2542 +5197 +5104 +3570 +4323 + +1631 +2406 +2788 +1838 +4639 +2469 +6718 +3731 +2375 +4325 +3952 +1012 +1076 + +10733 +9085 +5074 +9984 +9990 +10107 +9274 +10464 + +13249 +10020 +4881 +12806 +11865 + +9852 +6248 +4916 +7066 +5297 +5475 +6530 +10364 + +2415 +5519 +2200 +3556 +5815 +2426 +6180 +2142 +6627 +7369 +6353 +4170 + +5507 +15832 +15699 +10635 +7997 + +1742 +4641 +4628 +4867 +8860 +1133 +3575 +7128 +8774 + +2808 +6117 +3760 +1327 +1224 +4959 +5456 +2801 +5944 +1961 +1194 +3734 +2937 +3793 +1888 + +21943 +35720 + +6563 +5000 +1710 +4021 +3273 +6155 +3198 +3661 +6309 +2331 +1631 +5646 +5734 + +9646 +3457 +8620 +5965 +3440 +6433 +1753 +9062 +8301 + +9192 +3284 +9181 +8566 +3759 +10184 +8911 +6998 + +19491 +10283 +13574 +12306 + +2916 +9083 +13398 +13239 +4749 +12853 + +7223 +3154 +2911 +7004 +3110 +3584 +6619 +5960 +8429 + +5878 +4929 +4709 +4932 +3023 +1011 +2193 +4264 +5282 +1657 +4360 +6109 +5031 +3785 +5017 + +16065 +2923 +11281 + +7340 +3319 +5766 +1660 +7947 +7012 +2739 +1395 +8273 + +3887 +5538 +4771 +3770 +1504 +2681 +4066 +3406 +3487 +3098 +3611 +6234 +3449 + +12281 +11291 +11367 +10405 +4223 + +17411 +8453 + +36173 + +3431 +3627 +4047 +2512 +6628 +1229 +4812 +3961 +2389 +4747 +1799 +4291 + +2176 +7287 +6468 +3056 +9632 +1027 +3251 +1517 +1853 + +4727 +2417 +4544 +5949 +4289 +2237 +2861 +4284 +6912 +2843 +5773 +4423 + +3093 +6501 +1259 +4975 +4357 +2940 +2435 +2939 +1772 +3876 +5008 +2909 +5641 +5710 + +4559 +6522 +5781 +1343 +2062 +2392 +1852 +5135 +7668 +7240 +3028 + +11607 +9525 +7332 +11307 + +4941 +5277 +2311 +5738 +3029 +2709 +5448 +1724 +2982 +1082 +1515 +1854 +4762 +4514 +2015 + +51097 + +2814 +5593 +6576 +10591 +4809 +4469 +3790 +8186 + +7656 +10163 +19430 + +1928 +5626 +3418 +6785 +2781 +3549 +2884 +6656 +6210 +4950 +3598 +2669 +5185 + +8768 +5221 +7404 +9630 +3371 +9450 +1837 +3100 +4494 + +3987 +3179 +2415 +2074 +1172 +3192 +5874 +5869 +4404 +5842 +1987 +2526 +4094 + +5792 +6056 +1689 +5643 +4068 +2259 +1461 +1764 +3453 +2344 +6118 +5844 +2014 +1184 + +13505 +8242 +1358 +3817 +12030 +11105 + +7333 +9427 +10385 +3458 +6340 +10804 + +3152 +1364 +3371 +6000 +3032 +3326 +4046 +1890 +4321 +3986 +3309 +4021 +1683 +2198 +2003 + +2592 +8354 +13452 +12440 +7966 + +1593 +1143 +6246 +4105 +6164 +6425 +3904 +1143 +5966 +3100 +5215 +4256 +2090 +3413 + +4382 +6229 +2368 +1780 +5658 +1452 +6359 +1802 +3800 +6433 +3866 +3038 +4699 +4137 + +5395 +2426 +5621 +9156 +6250 +9008 +2966 +3226 +6709 + +5387 +7267 +6067 +6468 +5833 +5241 +7204 +1419 +6037 +5938 + +2390 +4300 +4787 +3656 +5976 +1879 +3964 +3314 +3076 +5158 +5612 +2846 +5231 + +2205 +3652 +5211 +1711 +2113 +5988 +1310 +5333 +2253 +2897 +5234 +3809 +3640 +2995 +2197 + +6695 +5930 +6118 +5463 +3750 +2440 +7006 +4073 +5663 +1369 +2721 +1961 + +5270 +4851 +5199 +1976 +4128 +5527 +2998 +1567 +6398 +4163 +1484 +6077 +3035 +3860 + +6698 +3081 +6805 + +13122 +4106 +6919 +6595 + +1608 +7971 +10279 +7856 +3503 + +7405 +6658 +3512 +3913 +6137 +2617 +2776 +8255 +7034 + +8368 +5163 +6566 +5481 +4059 +10560 + +5801 +5394 +2081 +2927 +1775 +1635 +1180 +5834 +7652 +2365 +6525 + +7192 +13806 +12580 +6935 +3136 +7820 + +2371 +7237 +5197 +1561 +2418 +1742 +5540 +7836 +1613 +4012 + +45767 + +6825 +6014 +7571 +3393 +2050 +8230 +4178 +5378 +4878 +5446 + +1412 +2156 +4877 +5604 +3149 +7585 +7922 +6811 +6971 +4493 + +12948 +32336 + +2512 +13073 +12030 +12851 +8951 + +3070 +10259 +2650 +6091 +5889 +4857 + +5483 +6813 +4208 +4999 +3708 +1955 +8588 +5416 +6235 +7920 + +2521 +7180 +7558 + +8285 +2208 +6058 +2839 +9653 +8078 +5862 +5711 +4847 + +3792 +1778 +3755 +13541 +12325 +9599 + +7431 +2814 +3828 +2468 +5499 +6822 +5190 +7279 +7939 +8488 + +5469 +3086 +8098 +12450 + +3182 +4307 +4150 +2802 +3857 +5331 +1045 +1111 +3983 +2606 +1077 + +3219 +2931 +4166 +2250 +5225 +1704 +3895 +6286 +1394 +5564 +1498 +3343 +5912 +2884 + +3874 +5309 +2941 +2109 +5322 +2994 +3922 +7538 +4666 +6223 +4754 + +4409 +6975 +8829 +4301 +1730 +2092 +2385 +1288 +9627 + +8849 +7371 +3259 +8823 +8963 +3901 +7003 +2250 +7492 + +7619 +16991 +7511 +5747 + +6361 +2401 +6509 +3429 +1276 +5120 +1852 +1706 +2373 +6117 +1967 +4655 +6193 + +3186 +10336 +12548 +7692 +1422 +7148 + +8898 +15230 +7468 +2349 +7214 + +18114 +7557 +10634 + +6755 +1045 +7326 +6511 +1691 +4966 +7367 +3305 +7083 +3105 +4262 + +6806 +8767 +6339 +4159 +11619 +8959 +10729 + +9070 +9027 +8532 + +2493 +1949 +5519 + +4637 +5893 +6617 +2710 +4712 +3514 +2828 +5131 +4756 +4772 +2488 +2540 +6593 + +4500 +9306 +3847 +8792 +4766 +10598 +5259 +1837 + +7936 +7125 +5091 + +4087 +6428 +3093 +5529 +2092 +5734 +1532 +1615 +5175 +4149 +6050 +2863 + +10505 +11702 +13870 +6381 + +12380 +6172 +16863 +9492 + +2406 +7906 +1139 +6866 +3963 +8280 +3315 +1645 +7885 +8315 + +2744 +10964 +9192 +6889 +11554 +4587 +5537 + +27485 +2819 + +67997 + +6372 +1910 +7440 +9638 +5161 +9354 +1063 +7999 +2712 + +6375 +6398 +2185 +11875 +1458 +11978 +9621 + +7326 +6319 +4988 +5326 +7844 +3876 +7311 +1920 +2865 +7959 +6890 + +5086 +3457 +3398 +6534 +5661 +1592 +4249 +1477 +3174 +3134 +6130 +2097 +5922 + +1854 +7848 +10289 +9261 +9692 +4814 +7798 +2634 + +13448 +10236 +11977 +4645 +12188 +11118 + +1681 +2162 +7349 +3198 +5725 +1151 +4940 +3481 +5896 +7245 +7424 +5630 + +3626 +3856 +4655 +1412 +2466 +5810 +4395 +1762 +4465 +3614 +3439 +6441 +4400 + +5037 +2450 +1870 +2191 +2145 +9754 +4259 +5762 + +9373 +3564 +7177 +1445 +8672 +4098 +6468 +1394 + +1675 +6754 +1996 +5894 +6449 +4644 +5642 +1338 +1087 +4989 +2467 +1192 +6368 + +34156 +12437 + +4394 +5648 +7691 +5598 +5720 +6414 +10089 +2116 + +9460 +2078 +7811 +13011 +5597 +1628 + +3772 +1201 +1174 +5884 +3720 +1120 +3830 +5809 +6269 +2548 +3212 +1924 +3951 +5178 + +1543 +7155 +5204 +7480 +9747 + +4029 +10517 +6776 +6978 +3517 +5746 +7683 +5939 + +5484 +1669 +1250 +3036 +3822 +5246 +1648 +5676 +1591 +1624 +3525 +4862 +2834 +5814 +4006 + +9610 +10230 +1473 +8541 +2163 +4706 +6919 +10514 + +46165 + +4618 +4867 +3750 +4578 +5498 +3468 +2663 +3003 +2777 +4434 +7386 + +18475 +5479 +15616 + +4810 +6199 +5905 +7014 +3903 +2404 +6955 +1290 +6328 +4729 +1567 +2070 + +1426 +6652 +7274 +3535 +1873 +8830 +6465 +3091 + +11667 +1824 +1749 + +6031 +1589 +6764 +5294 +2658 +7540 +2285 +5290 +3052 +4809 + +9275 +3219 +9205 +9367 +6695 +1620 +1418 +9589 +6985 + +4961 +1893 +4204 +4158 +2488 +6562 +6862 +7443 +5180 +6382 +5930 +2819 + +9225 +17113 +2562 +11634 + +9490 +5720 +2413 +13607 +12761 +4473 + +10788 +18449 +9511 + +11498 +3288 +9304 +4951 +10878 + +13888 +23233 +18690 + +5112 +9811 +9336 +4030 +11021 +3585 +1534 + +6026 +5618 +3065 +2909 +8887 +8052 +3524 +7783 +5793 + +3573 +5391 +1887 +6295 +3311 +8235 +3985 +2222 +2594 + +2807 +3623 +2622 +6466 +2272 +2181 +5550 +4568 +1172 +2579 +1020 +5542 +2653 +1080 + +4874 +10296 +5421 + +3743 +5053 +5510 +1401 +4173 +7968 +5999 +6482 +7019 +7916 +3752 + +8718 +7969 +6072 +3223 +5924 +2642 +8274 +1985 +3342 +2036 + +1706 +8655 +3521 +7502 +7955 + +1915 +5083 +1668 +11457 +2011 +9998 +9885 + +10592 +25078 +17582 + +2596 +2198 +8811 +7464 +5711 +7197 +8744 +5382 +6179 +3769 + +3713 +6012 +7951 +10750 +5580 +3426 +11019 + +5536 +7943 +5163 +7703 +14144 + +3169 +5475 +2367 +3666 +6042 +4279 +1699 +3129 +3294 +1813 +6465 +3591 +3332 +2155 + +1305 +9537 +9805 +2172 +8665 +8386 +7718 +10709 + +4645 +6242 +8462 +6619 +3165 +7797 +5664 +5058 +1339 +3749 + +3365 +5018 +3278 +3403 +4138 +4521 +1797 +3791 +1401 +3748 +6039 +1513 +2696 diff --git a/2022/day1/part1/Cargo.toml b/2022/day1/part1/Cargo.toml new file mode 100644 index 0000000..f14fe90 --- /dev/null +++ b/2022/day1/part1/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "part1" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +itertools = "0.10.5" diff --git a/2022/day1/part1/example b/2022/day1/part1/example new file mode 100644 index 0000000..2094f91 --- /dev/null +++ b/2022/day1/part1/example @@ -0,0 +1,14 @@ +1000 +2000 +3000 + +4000 + +5000 +6000 + +7000 +8000 +9000 + +10000 diff --git a/2022/day1/part1/src/main.rs b/2022/day1/part1/src/main.rs new file mode 100644 index 0000000..637b4e3 --- /dev/null +++ b/2022/day1/part1/src/main.rs @@ -0,0 +1,14 @@ +use itertools::Itertools; + +fn main() { + let input: String = include_str!("../../input").to_string(); + let mut calories: Vec = Vec::new(); + + for (key, group) in &input.lines().group_by(|line| *line != "") { + if key { + calories.push(group.into_iter().map(|i| i.parse::().unwrap()).sum()); + } + } + + println!("{}", calories.iter().max().unwrap()); +} diff --git a/2022/day1/part2/Cargo.toml b/2022/day1/part2/Cargo.toml new file mode 100644 index 0000000..69fa504 --- /dev/null +++ b/2022/day1/part2/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "part2" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +itertools = "0.10.5" diff --git a/2022/day1/part2/example b/2022/day1/part2/example new file mode 100644 index 0000000..2094f91 --- /dev/null +++ b/2022/day1/part2/example @@ -0,0 +1,14 @@ +1000 +2000 +3000 + +4000 + +5000 +6000 + +7000 +8000 +9000 + +10000 diff --git a/2022/day1/part2/src/main.rs b/2022/day1/part2/src/main.rs new file mode 100644 index 0000000..2a65d1a --- /dev/null +++ b/2022/day1/part2/src/main.rs @@ -0,0 +1,21 @@ +use itertools::Itertools; + +fn main() { + let input: String = include_str!("../../input").to_string(); + let mut calories: Vec = Vec::new(); + + for (key, group) in &input.lines().group_by(|line| *line != "") { + if key { + calories.push(group.into_iter().map(|i| i.parse::().unwrap()).sum()); + } + } + + println!( + "{}", + calories + .iter() + .sorted_by(|a, b| Ord::cmp(b, a)) + .take(3) + .sum::() + ); +} -- cgit v1.2.3-70-g09d2