diff --git a/2022/day1-input b/2022/day1-input new file mode 100644 index 0000000..f10d8a8 --- /dev/null +++ b/2022/day1-input @@ -0,0 +1,2248 @@ +2159 +2527 +2441 +3299 +1672 +3025 +2820 +6821 +3201 +1204 +1208 +4861 +5621 + +5580 +18071 + +8803 +1667 +4173 +9404 +9718 +10311 + +12237 +5068 +9824 +6535 + +25484 + +18598 +2851 +13577 + +13719 +9147 +11204 +8554 +11796 +1297 + +43055 + +8156 +4616 + +16383 +17036 +16017 +18569 + +33581 +10017 + +65566 + +5750 +6961 +4494 +11117 +3392 +10471 +3490 + +7006 +7526 +9302 +1454 +4039 +8067 +9321 +8888 +7380 + +8543 +2106 +2986 +3465 +9592 +11240 +1795 + +4396 +27967 + +8091 +19515 +1282 + +6241 +8946 +6665 +5163 +2224 +8684 +6631 +5866 + +5565 +6118 +1856 +3227 +4501 +3024 +5745 +3988 +1590 +5111 +4457 +3108 +3165 +3508 +4629 + +1455 +4809 +5650 +5472 +4673 +1775 +3080 +5282 +3552 +3875 +4691 +7352 + +7325 +2121 +2751 +10300 +1939 +3782 +3635 +1801 + +8562 +15236 +18996 +18271 + +9673 +9270 +15540 +5842 +10343 + +7384 +30187 + +7578 +7909 +8514 +5775 +3455 + +2617 +30132 + +6414 + +6916 +6847 +2774 +2137 +2755 +3801 +5635 +2354 +5206 +1555 +1979 +4146 +3223 + +25686 +20293 + +17083 +16276 +14249 +19080 + +11875 +14353 +5177 +9053 +13032 + +2168 +4155 +6764 +3432 +6362 +5193 +1953 +6809 +2592 +2940 +1712 +4140 +2971 + +6197 +5203 +10968 +10361 +9549 +9288 +4285 + +12639 +6370 +9415 +13404 +1185 + +40195 + +5865 +4919 +1593 +2182 +4134 +4928 +2521 +3529 +3780 +4039 +4554 +1449 +5414 +1335 +3145 + +5323 +10950 +6223 +4568 +4096 +5697 + +2252 +3388 +1881 +5937 +4571 +1266 +5451 +3547 +2718 +5851 +5127 +4469 +3896 +5401 + +10727 +3611 +3924 +9410 +8255 +4973 +9845 + +13643 +6910 +7722 +4082 +4449 +10901 + +2193 +1347 +1070 +7345 +6916 +7148 +2948 +5325 + +2121 +9029 +4972 +6004 +10500 +8962 +5505 +5541 + +5862 +2143 +6882 +7117 +7377 +1663 +5025 +3543 +5279 +2009 +3243 +2738 + +11713 +36062 + +4486 +7936 +3497 +9095 +10365 +11350 +2871 + +11207 +7344 +4568 +4303 +4564 +3537 +9306 + +2713 +2131 +5390 +1658 +3888 +4057 +2415 +1206 +5894 +6019 +2675 +5690 +1396 +1211 +5796 + +1614 +2036 +3825 +1868 +1695 +5456 +6781 +3703 +5360 +4286 +2098 +4870 +1774 + +3024 +10027 +11951 +12395 +7235 +12217 + +3526 +2302 +5594 +5210 +1700 +3858 +2282 +5079 +3805 +5202 +2637 +3713 +4628 + +1236 +1025 +5147 +1707 +1968 +1957 +3236 +1304 +4445 +1113 +3339 +1600 +4387 +5561 +4067 + +10142 + +11218 +9160 +11751 +12770 +13082 +11308 + +2902 +7986 +1353 +11697 +9091 +9758 +5959 + +30995 +4880 + +51409 + +2447 +3702 +3691 +3799 +5245 +4059 +3995 +4062 +4306 +4831 +4983 +2675 +1957 +4448 +4466 + +4526 +3559 +2859 +6809 +4220 +7802 +1842 +5260 +7885 +4327 + +4108 +10738 +3790 +10063 +2151 +1109 +6287 + +9668 +4537 +9819 +7653 +5472 +9815 +6801 +10064 + +6506 +6381 +2925 +1827 +8351 +7893 +1534 +3095 +3371 + +4751 +2425 +4391 +3993 +6915 +2815 +1171 +4244 + +1989 +4356 +2356 +1155 +6421 +1276 +5180 +1234 +5162 +1572 +5139 +5039 +4044 +3196 + +6301 +1677 +3682 +6065 +4279 +2823 +3820 +1689 +2880 +3858 +4057 +1718 +2341 +2609 + +13112 +9850 +7687 +3533 +13436 + +3221 +2511 +2034 +2518 +1429 +1115 +2292 +5982 +3859 +4813 +3884 +3766 +1398 +1307 +1114 + +8116 +8158 +8281 +4972 +9848 +7207 +2000 +8389 + +5534 +5354 +2736 +4137 +2232 +3363 +6423 +5242 +4889 +5954 +1269 +3836 + +34199 +1010 + +5347 +19266 +6151 + +7355 +9264 +15405 + +5659 +2466 +5593 +1615 +1035 +3464 +4237 +5532 +4739 +3202 +4018 +4355 +5047 +1085 +5701 + +1855 +3764 +4400 +3316 +6592 +5938 +4181 +5686 +4982 +3172 +5083 +3553 +4031 + +7043 +9662 +6165 +1007 +6016 +2782 +1859 +3957 +8388 + +15153 +7559 +19575 +5262 + +31900 +13395 + +51487 + +14907 +31794 + +1450 +9954 +3039 +5989 +1723 +11802 +10238 + +2404 +7669 +11121 +10550 +5239 +4153 + +5193 +4785 +5851 +1417 +1957 +2102 +4458 +1712 +4914 +1195 +3235 +3552 +4482 +2651 + +5531 +4364 +4775 +3752 +3298 +4680 +2183 +3576 +2079 +4577 +5104 +5725 +2396 +4339 +5199 + +4231 +6177 +3676 +5690 +5114 +6936 +4726 +1769 +4865 +1013 +3706 +2990 +2569 + +1007 +3622 +2266 +1993 +5089 +2966 +6259 +7076 +2134 +2902 +3218 +7279 + +1326 +3004 +4093 +4220 +4447 +3847 +4168 +5216 +5744 +2389 +5589 +4004 +1817 +3621 +5296 + +13987 +18409 +17832 +11535 + +11649 +8919 +18521 +14161 + +1415 +4887 +3494 +5247 +6589 +6843 +2835 +5927 +4117 +1156 +6928 +4561 +1090 + +8282 +10239 +8219 +6655 +9963 +10672 +2648 +9472 + +2684 +5383 +2257 +5979 +5831 +3924 +2830 +5286 +4345 +2823 +2637 +3323 +3713 +3054 +4266 + +3794 +3481 +4462 +6962 +3036 +1331 +2209 +2207 +6242 +6425 +7935 + +4035 +5276 +2420 +2056 +7858 +2502 +5326 +3403 +5849 +1839 +7903 + +2471 +1515 +4700 +2824 +3543 +5832 +3984 +3338 +3439 +4061 +5929 +2455 +3231 + +7861 + +9304 +3161 + +2371 +28263 + +1661 +1388 +2995 +12665 +16419 + +2524 +1487 +7060 +3838 +1578 +7169 +5209 +7784 +3624 +4459 +2364 + +6698 +1301 +9506 +6294 +7991 +8888 +8743 +6054 + +12685 +5876 +5168 +7008 +10315 + +6748 +1470 +2574 +8676 +1931 +8141 +1363 +5511 +5202 +7192 + +1594 +4407 +2553 +6004 +5681 +1238 +6153 +5082 +2080 +2167 +4224 +4983 +5011 +4437 + +4646 +1839 +3847 +2657 +1961 +6910 +2504 +3201 +2122 +1368 +3298 + +9041 +8226 +4741 +9802 +8968 +1241 +8769 +9428 + +3818 +2525 +2976 +2435 +4602 +7466 +8117 +8330 +4226 + +3773 +6191 +1045 +3874 +7811 +4758 +6726 +4243 +7139 +8009 +1763 + +6146 +7887 +1934 +1107 +8833 +3816 +7822 +7614 +2084 + +4729 +4535 +3489 +3971 +3995 +1261 +2723 +6688 +1397 +6089 +1039 +1162 +2845 + +14666 +23256 + +1183 +4264 +1316 +2549 +4763 +4966 +6321 +6230 +4309 +2484 +4915 +6496 +6628 + +12678 +3479 +7812 + +2773 +6383 +7824 +2647 +4234 +3274 +6620 +1696 +4621 +1662 + +13710 + +11861 +4939 +3810 +13818 +7577 + +2840 +3547 +4020 +1876 +5041 +5290 +6509 +4969 +3490 +2539 +5644 +2279 +1848 +5828 + +11719 +11125 +3216 +11005 +11633 +2806 + +49621 + +9289 +1576 +7377 +8217 +1445 +5638 +3544 + +1610 +11356 +18332 +6800 + +2308 +4086 +1765 +6148 +1291 +6606 +5974 +7110 +3515 +5511 +3222 +5222 + +10477 +9350 +8515 +9846 +7086 +9324 +3376 +7061 + +3618 +2702 + +4829 +3094 +5689 +1657 +4491 +6307 +6404 +5355 +6493 +6159 +3149 +5458 +3639 +4575 + +16698 +23747 +7188 + +6495 +3976 +7676 +4560 +7326 +6772 +5877 +7121 +6474 +6104 +1811 + +3745 +5935 +16652 +19074 + +1050 +1684 +6531 +1365 +4615 +5569 +4257 +4619 +3576 +5736 +2284 +4054 +4736 + +11520 +5079 +6733 +7453 +10370 +10336 + +13082 +5970 +5552 +4886 +3365 +2465 + +8226 +1767 +1330 +7254 +4164 +2254 + +3745 +3173 +3378 +6116 +2539 +2548 +6082 +5685 +2572 +5908 +3721 +4079 +6028 +4928 + +6065 +10833 +18151 +9597 + +6461 +6590 +6341 +7117 +2508 +4495 +5848 +3721 +3139 +6980 +3020 +6416 + +1772 +5253 +1476 +12001 +7434 +9614 + +3821 +7137 +6955 +3022 +4107 +2381 +4975 +2041 +1391 +6479 +4380 + +27486 +23127 + +2754 +5361 +3334 +1119 +2534 +6649 +1333 +6055 +4740 +4282 +6868 +2203 + +13576 +11551 +9609 +13727 +7950 +8594 + +2078 +6350 +11475 +7410 +11617 +4156 +6565 + +5466 +1887 +2844 +2386 +3286 +2369 +4826 +5052 +1605 +3638 +2464 +1256 + +4612 +4885 +4738 +5946 +5822 +2629 +1701 +3454 +2385 +2256 +5738 +5355 +4582 +2256 +6109 + +8280 +12911 +12759 +7058 +5658 +8825 + +4352 +1600 +2414 +3442 +7060 +3618 +3681 +6777 +4115 +7295 +3032 +5935 + +15976 +15624 +8838 +16884 + +4206 +6660 +3702 +3294 +5066 +5153 +2687 +2138 +2387 +2640 +2887 +4689 +1592 + +6347 +6804 +7760 +3433 +4076 +3360 +6994 +4539 +4413 +3747 +3856 + +12149 +23188 +17235 + +1676 +3699 +3827 +2440 +6046 +4516 +3452 +4108 +2240 +4454 +1850 +1907 +6039 +4589 +1028 + +1447 +4080 +2846 +2959 +3580 +3422 +3876 +2805 +2184 +6175 +4826 +2002 +5567 +4959 + +3545 +7160 +3584 +7979 +8150 +2598 +1528 +8569 + +2705 +2584 +6312 +5107 +6674 +6737 +4977 +7302 +2154 +7072 +1874 +2860 + +25044 +21875 +11897 + +10493 +4494 +11775 +7689 +2241 +11089 +6639 + +4732 +2438 +6095 +4217 +2815 +2179 +1388 +1050 +1686 +4542 +2692 +2624 +4548 +4158 +1554 + +5549 +4680 +5028 +2004 +2803 +6145 +4969 +4637 +7026 +6769 +1347 +1023 + +8246 +7712 +3191 +6860 +8708 +1435 +5973 +2667 +5426 + +4128 +1662 +3235 +2343 +5648 +6688 +6622 +2625 +3453 +5599 +5757 +5799 +1461 + +4777 +9486 +7167 +4960 +6227 +2074 +5197 +4242 + +1412 +1861 +7599 +5993 +5588 +2494 +8105 +1902 +3187 +1945 + +3792 +3070 +4611 +5463 +4745 +7237 +5579 +2036 +2605 +6729 +4963 +1694 + +8441 +8372 +8617 +3295 +10245 +3520 +1524 +2418 + +6328 +2063 + +19738 +10056 +16085 +2863 + +5697 +1102 +5817 +1447 +3060 +2563 +5476 +2389 +2258 +2439 +2059 +5751 +4874 +4629 +1591 + +15007 +7626 + +12623 +23823 +17194 + +55217 + +10620 +11397 +4761 +11650 +13208 +2508 + +4106 +3845 +2383 +1389 +4701 +4674 +6075 +4917 +6815 +1790 +2452 +5396 +2949 + +20219 +10699 +1223 + +4720 +1107 +5354 +6254 +5367 +3808 +4687 +1253 +3580 +6658 +8084 + +5861 +4207 +5535 +12800 +4588 +2333 + +7203 +36816 + +5985 +5394 +5689 +2730 +1034 +6016 +3903 +5419 +4802 +2792 +1209 +4412 +2835 +5574 +1721 + +9837 +11425 +5676 +7511 +11236 +10062 +11180 + +1574 +4254 +2501 +5256 +6071 +3180 +6302 +1019 +6345 +2041 +2556 +5173 +3686 +2862 + +1622 +3929 +8097 +3392 +9603 +6645 +9101 +8963 + +9677 +1115 +2716 +8048 +9394 +7321 +9496 + +10805 +10286 +10947 +5896 +7808 +1791 +11995 + +1886 +2697 +5634 +4818 +2213 +1927 +7440 +7311 +6638 +4760 +3677 +1648 + +18334 + +1424 +5646 +4407 +3184 +6817 +6297 +2689 +3783 +1809 +3542 +2829 +5268 +3934 + +10276 +16236 +13013 +11052 +5967 + +9245 +1505 +6473 +1173 +10126 +4803 +1874 +1397 + +3377 +5662 +4181 +4311 +2313 +7453 +3734 +3438 +2304 +5807 +4041 +2673 + +42104 + +4047 +6040 +8950 +5913 +3512 +7760 + +6321 +4745 +7073 +2117 +3427 +6842 +5525 +5870 +2418 +1926 +7264 +1591 + +1223 +9775 +14018 +15378 + +12574 + +10520 +3487 +8520 +6708 +7996 +11442 +2206 + +11255 +4890 +3493 +4284 +5313 +11598 + +2982 +21019 + +1915 +3312 +4851 +7937 +4442 +1259 +6454 +6212 +8728 + +16012 +31825 + +3090 +15799 +14109 +8736 +11302 + +4835 +5319 +4717 +2968 +3703 +3892 +6247 +3263 +2850 +1889 +2989 + +6923 +6909 +7498 +3434 +5755 +1982 +1577 +4303 +2399 +2424 +5726 + +17813 +12904 +17003 + +3194 +12390 +11283 +2694 +8006 +11555 + +5094 +3057 +7671 +8755 +4429 +3076 +3283 +3984 +2460 +1720 + +6285 +5638 +5352 +1032 +5500 +5093 +4972 +6139 +2477 +4845 +1977 +3396 +1298 +4563 + +10996 +5188 +8022 +7555 +2353 +13208 + +1770 +1563 +1282 +8442 +6443 +1430 +3077 +4630 +8869 + +4633 +2671 +6720 +6390 +4815 +5276 +5639 +4067 +1325 +2563 +5760 + +5091 +12562 +4601 +6905 +12067 + +5632 +3856 +2885 +3090 +5837 +1604 +4805 +1957 +4769 +6524 +6473 +1126 +4044 + +5449 +7915 +10347 +5347 +1548 +5313 +6816 +9401 + +2918 +3990 +3690 +3351 +6178 +6373 +3551 +1288 +4961 +5867 +5061 +6706 +1849 + +3745 +2090 +4216 +6031 +5888 +6238 +2951 +4671 +6451 +5536 +5177 +6089 +6062 +1157 + +2759 +5545 +3896 +2474 +4101 +6321 +7415 +7326 +7131 +4581 +3243 +3782 + +6470 +3540 +4160 +7171 +7946 +4097 +1142 +5022 +6545 +4889 +4762 + +2709 +3765 +1880 +2601 +2312 +5789 + +11191 +7016 +19716 +4196 + +1903 +3391 +1491 +5481 +3306 +2093 +4878 +3301 +4961 +3398 +5579 +5558 +3669 + +4402 +1781 +4861 +3633 +6699 +9137 +3165 +7754 + +14784 +7543 +4446 +9325 +13613 + +5355 +2452 +2153 +4075 +5333 +5572 +3105 +4848 +1124 +4715 +5375 +1614 +2580 +2188 +4713 + +1560 +4565 +4367 +4621 +4981 +2504 +4394 +5528 +5537 +2486 +1553 +7379 + +35695 + +9647 +8727 +6135 +3147 +8616 +6873 +3837 +7376 +5415 + +2648 +2742 +5116 +6315 +5150 +4049 +4783 +4102 +1808 +4138 +6134 +1439 +5609 + +15163 +10151 +1869 +12214 + +6504 +5302 +2124 +2330 +1460 +3671 +1086 +1919 +2766 +3156 +5680 +4024 +3160 +4793 + +4243 +17053 +22756 + +5103 +2752 +3162 +4466 +3569 +1656 +4430 +3378 +2581 +3847 +5479 +2378 +3720 + +68321 + +5590 +3509 +2669 +2430 +3234 +3403 +6124 +6024 +3407 +6400 +2780 +6322 +5139 +1618 + +6471 +2418 +3991 +5206 +1343 +2674 +4228 +4816 +2144 +5542 +2555 +5055 +4481 +2239 + +3605 +1063 +2534 +4631 +3836 +3967 +3373 +5778 +5698 +3580 +2214 +5307 + +2961 +2388 +1769 +6464 +6452 +2944 +4196 +3566 +4218 +5808 +1712 +1488 +2127 +5959 + +6828 +4662 +2844 +9182 +1912 +4558 +4760 +2042 +5317 + +1911 +1235 +5583 +5971 +7786 +10324 +6978 +7148 + +4537 +5225 +2886 +8229 +8611 +9025 +2229 +9990 + +6005 +4924 +1458 +2998 +2809 +3068 +5967 +2003 +4161 +2227 +4010 +2429 +1088 +3286 +1814 + +1524 +1882 +2661 +1868 +2448 +4244 +4882 +4113 +4866 +3652 +5468 +2841 +5572 +3431 + +4971 +6486 +5373 +5863 +7378 +7901 +1803 +4637 +2088 +7780 +6047 + +7458 +2483 +5279 +2673 +5310 +7321 +1520 +1117 +1078 +2879 +7379 +5757 + +1030 +10099 +10427 +6213 +12215 +4307 + +1157 +2020 +5233 +1997 +7472 +2968 +2847 +3744 +6340 +3310 +3237 +1519 + +26488 + +16807 +24831 +13009 + +9601 +1567 +8861 +2226 +7238 +6549 +8867 +9238 + +2573 +3677 +10657 +8167 +1435 +10753 + +8808 +4328 +3503 +6761 +6209 +2579 +2896 +2441 +1370 +2880 + +38579 + +3846 +3357 +6584 +6682 +2620 +3197 +1914 +2873 +2158 +6229 +3507 +3003 +1051 + +5816 +5885 +4040 +6485 +1984 +4185 +2024 +5446 +1961 +4646 +3395 +6606 +3919 + +1961 +4181 +10805 +5917 + +7241 +6129 +5211 +4923 +9200 +5140 +5847 +8434 +3620 + +3216 +3066 +2708 +6310 +2403 +2018 +2405 +6625 +1317 diff --git a/2022/day1.scala b/2022/day1.scala new file mode 100644 index 0000000..7d586d8 --- /dev/null +++ b/2022/day1.scala @@ -0,0 +1,33 @@ +import scala.collection.mutable.ArrayBuffer +import scala.io.Source + +class Elf: + var foodCalories = List[Int]() + var totalCalories = 0 + + def calculateTotalCalories(): Int = + totalCalories = foodCalories.sum + totalCalories +end Elf + + +val filename = "day1-input" + + +@main def main() = + val elves = ArrayBuffer[Elf](Elf()) + for (line <- Source.fromFile(filename).getLines) + if line.isEmpty then + elves.last.calculateTotalCalories() + elves.addOne(Elf()) + else + elves.last.foodCalories = line.toInt :: elves.last.foodCalories + elves.last.calculateTotalCalories() + + // for (elf <- elves) + // println(s"${elf.totalCalories}: ${elf.foodCalories}") + + // Part 1 solution: Total calories held by elf with the most total calories + println(s"${elves.map(elf => elf.totalCalories).max}") + // Part 2 solution: Total calories held by the top 3 elves + println(s"${elves.map(elf => elf.totalCalories).sorted.takeRight(3).sum}")