diff --git a/2022/aoc2022.cabal b/2022/aoc2022.cabal index 0ac7cd8..126a3ca 100644 --- a/2022/aoc2022.cabal +++ b/2022/aoc2022.cabal @@ -32,3 +32,4 @@ executable aoc2022 build-depends: base ^>=4.16.3.0 hs-source-dirs: app default-language: Haskell2010 + other-modules: Day1.Main diff --git a/2022/app/Day1/Main.hs b/2022/app/Day1/Main.hs new file mode 100644 index 0000000..d0c2df8 --- /dev/null +++ b/2022/app/Day1/Main.hs @@ -0,0 +1,32 @@ +module Day1.Main (main) where + +import Data.List +import System.IO +import Control.Monad + +main :: IO () +main = do + putStrLn "Day 1" + + handle <- openFile "app/Day1/input" ReadMode + contents <- hGetContents handle + + let r1 = part1 contents + putStrLn $ "part 1: " ++ show r1 + + let r2 = part2 contents + putStrLn $ "part 2: " ++ show r2 + +parseInput :: String -> [Int] +parseInput contents = map sum foodItems + where + input = lines contents + elves = foldr (\a b -> if a == "" then [] : b else (a : head b) : tail b) [[]] input + foodItems = (map . map) (read :: String -> Int) elves + +part1 :: String -> Int +part1 = maximum . parseInput + +part2 :: String -> Int +part2 = sum . (take 3) . reverse . sort . parseInput + diff --git a/2022/app/Day1/input b/2022/app/Day1/input new file mode 100644 index 0000000..eff7a41 --- /dev/null +++ b/2022/app/Day1/input @@ -0,0 +1,2249 @@ +5794 +5879 +4899 +6777 +5845 +1303 +6761 +1814 +6605 +4715 +2264 +2789 + +4684 +6694 +5840 +2705 +7269 +2127 +4265 +3944 +1134 +2623 +5617 +7191 + +5293 +6742 +4208 +3218 +5967 +1617 +5433 +2938 +6337 +6694 +1597 +5727 +1734 + +1745 +15953 +3781 + +18680 +3460 +21833 + +7434 +7346 +1116 +4079 +5013 +4597 +3730 +3660 +1595 +4501 +5908 +4847 + +4357 +5306 +4632 +4808 +7222 +2487 +3772 +4656 +2316 +1876 +3029 +6280 + +5298 +15504 +5338 +15522 +7264 + +4253 +6912 +8254 +8559 +6364 + +9485 +12425 +10047 +2934 +6686 +11651 + +7701 +4660 +3241 +10868 +7111 +7973 +6048 + +1549 +4669 +4199 +6211 +5297 +5535 +7972 +1615 +8711 +3803 + +2562 +3344 +6535 +4892 +5025 +1972 +1734 +2671 +3380 +3682 +3990 +3602 +6649 + +1641 +3404 +4608 +10732 +2157 +3435 +4416 +6776 + +5487 +8946 +7325 +9531 +4851 +4976 +9406 +4848 +9058 + +1883 +7711 +9300 +5638 +8096 +2885 +4520 +3024 + +6044 +3910 +5663 +5250 +13826 +1469 + +56667 + +2437 +4404 +6875 +4034 +3906 +7256 +1054 +1436 +7231 +3858 +6880 +6449 + +4737 +1421 +3682 +1389 +4492 +4821 +3875 +2907 +4357 +3759 +3224 +5005 +5712 +3098 +5864 + +2407 +4258 +7987 +2085 +1802 +2838 +5100 +5815 +4602 +1617 +8058 + +13874 +16855 +12120 +12266 + +16448 + +1693 +5327 +1443 +3932 +4648 +2142 +6757 +5190 +2704 +4759 +2954 +4681 +2702 + +1525 +4403 +6818 +6125 +2535 +3955 +1859 +2265 +5915 +3137 +1961 +6610 +2133 + +8152 +10276 +10852 +10244 +1459 +8134 +6686 + +1807 +3470 +3171 +8803 +6592 +6954 +3109 +3305 +2393 +8381 + +1688 +4232 +5952 +4896 +5610 +3247 +3249 +2628 +3325 +1628 +4876 +3829 +4656 +2871 +3571 + +4133 +1826 +8072 +9227 + +5784 +6032 +1491 +3691 +1206 +4398 +4794 +5852 +3215 +1779 +2362 +2175 +3580 +1929 +5469 + +7469 +4215 +7364 +4310 +5277 +4668 +1030 +6087 +7521 +2959 +2878 + +1672 +6020 +6047 +3580 +5766 +5859 +3605 +5630 +6545 +3512 +2841 +7216 + +4731 +9911 +11359 +13234 +11676 +8120 + +6618 +24252 + +1530 +5230 +7254 +8009 +9010 +9620 +5119 +4598 +9687 + +5159 +5686 +1788 +5088 +1938 +4131 +4612 +6038 +4220 +4521 +1550 +4918 +2501 +2504 +3077 + +4439 +5145 +10897 +5844 +3709 +4495 + +4139 +5134 +5328 +5474 +6064 +2589 +2809 +1653 +1494 +3337 +5593 +2546 +2905 +1093 + +6920 +4134 +3878 +2094 +2573 +3692 +1148 +2302 +5412 +3658 +3024 +4709 +3181 + +24826 +21716 +12659 + +5770 +7224 +5016 +6369 +5626 +2550 +7297 +4664 +4919 +2545 +6251 +3846 + +7482 +7360 +8577 +5502 +2145 +3763 +6408 +4769 +6610 + +5739 +2098 +2385 +5588 +2409 +3387 +3623 +1372 +4403 +6322 +6026 +4003 +2653 +1568 + +66601 + +3188 +13831 +10244 +1496 +12540 +11285 + +5301 +17714 +18376 + +4464 +4720 +4548 +1519 +1955 +1675 +3495 +6326 +3434 +2450 +1450 +6297 +2557 + +5980 +13288 +1545 +12018 +7961 +6012 + +7880 +4981 +9901 +7816 +3172 +9490 +10029 +8410 + +12095 +10481 +10933 +4235 +1106 +9284 +3133 + +7579 +6723 +4875 +6147 +2017 +2566 +7641 +5163 +5477 +1134 +1661 + +7135 +1013 +3218 +2549 +7639 +7299 +3924 +1942 +3199 +7851 +1217 + +2512 +4356 +2482 +1178 +4521 +3400 +4333 +1726 +6308 +6277 +1143 +4962 +2837 +6507 + +1305 +6109 +3115 +1205 +2172 +3416 +5558 +5227 +6017 +4503 +3088 +1560 +5945 +3679 +5448 + +2977 +9069 +4530 +12642 +1821 + +4452 +19214 +14527 +19883 + +6361 +5748 +5999 +2580 +6697 +5402 +2422 +3183 +5503 +5993 +2567 +4208 +2004 + +22562 + +2656 +1112 +5664 +5517 +1301 +2184 +1646 +2851 +4817 +5350 +4074 +2133 +6169 + +3933 +8419 +7256 +6770 +3469 +1438 +11003 + +1456 +5635 +1933 +1196 +6686 +3245 +2141 +6819 +5743 +3614 +2485 +6829 +5244 + +10649 +30106 + +4766 +4779 +4134 +3761 +3088 +5477 +1892 +3585 +5867 +2566 +1960 +1922 +1577 +2091 + +19270 +29017 + +3108 +10282 +4623 +10377 +3570 +6322 +6958 +7057 + +35355 +25911 + +31705 + +12443 +2062 +1464 +8206 +3083 +13052 + +19188 +16088 +3927 +11479 + +2421 +5453 +2946 +3118 +2456 +5152 +5604 +2909 +2020 +5040 +7498 + +10666 +5120 +10166 +6616 +2151 +6102 + +4463 +32308 + +6447 +6712 +1183 +4264 +1824 +1533 +1403 +7320 +2204 +1865 +1887 + +13860 +5324 +10272 +10859 +1615 +1345 + +21147 +20301 +24255 + +57301 + +16407 +9592 +3822 +11186 +9812 + +2436 +9609 +5163 +6263 +4182 +10301 + +22997 +3077 +15477 + +2379 +5970 +5429 +1283 +4580 +4126 +2592 +6285 +2669 +1612 +6320 +5087 +2941 +6433 + +33200 + +6861 +9236 +1301 +12712 +14165 + +8933 +5205 +11578 +1523 +10091 +7515 + +2376 +11526 +15587 +13513 +12834 + +4796 +2358 +6422 +4603 +6920 +3971 +1899 +7821 +3885 +1718 +8039 + +16063 + +4537 +6714 +1857 +5871 +6182 +9996 +4217 +6483 + +5059 +4145 +3818 +3898 +3896 +3085 +4477 +1476 +6014 +3545 +5200 +5363 +5866 +3218 +2466 + +5648 +4125 +4125 +4912 +3651 +6606 +2230 +6221 +6480 +7240 +7302 +5600 + +2273 +3832 +3343 +2207 +1359 +5842 +5131 +4928 +3466 +6427 +3191 +6623 +1885 + +1158 +1687 +6243 +8632 +2634 +9070 +4482 +3477 +8077 + +1593 +1220 +2601 +3283 +5779 +5161 +6210 +4752 +1137 +7443 +3161 +5268 + +8847 +3825 +5688 +6218 +4998 +10218 +9792 + +3549 +1562 +11437 +6479 +4094 +1537 +11888 + +7069 +4924 +7235 +7244 +4942 +6144 +5175 +1472 +5395 +1776 +6968 +6417 + +5962 +5599 +11740 +3693 +11159 +9934 +10682 + +6246 +23393 +3247 + +64480 + +28558 +23959 + +4732 +4052 +4660 +2032 +2537 +6107 +4976 +1510 +2342 +2037 +1961 +2120 +3331 +5388 +2840 + +4738 +4435 +9965 +10755 +9136 +2779 +3494 +7568 + +11962 +12956 +12901 +1053 +15933 + +8344 +4378 +4982 +8580 +5246 +4652 +1197 +1209 +4898 +2905 + +7828 +2797 +6653 +3897 +11216 +4896 +5650 + +5060 +5783 +1814 +4749 +1884 +2609 +6175 +5615 +6674 +4203 +6060 +1345 +5485 + +6323 +5968 +3726 +3863 +2986 +2218 +2389 +6289 +4369 +2472 +5961 +4442 +4902 +2875 + +5480 +2082 +1907 +3069 +6594 +6621 +6692 +3164 +4281 +5764 +2844 +5682 + +4652 +3059 +1388 +7547 +7804 +5770 +4792 +4181 +5903 +6609 +4468 + +5470 +1039 +13220 +6244 +12612 +6790 + +3762 +1435 +6236 +5328 +5577 +4420 +5485 +6727 +3656 +3583 +1089 +3468 +4795 + +19632 + +10092 +3698 +4674 +10270 +4097 +8378 +9019 +2101 + +4001 +7242 +7841 +7903 +8072 +2704 +3750 +1335 +9390 + +5466 +8448 +4827 +3673 +2489 +7995 +3362 +6592 +1453 +2353 + +10382 +15140 +10465 +7746 + +1061 +3623 +9453 +8621 +10641 +8431 +9650 +8132 + +13431 +4971 + +10121 +9985 +8609 +5410 +9424 +1115 +8339 +1319 + +1991 +5002 +6099 +3845 +5373 +5072 +6950 +7134 +4229 +6917 +2796 +3188 + +6805 +2159 +1436 +6231 +1280 +5023 +3806 +3864 +1801 +5281 +3623 +3162 +6226 + +14847 +1007 +1553 +15502 +5373 + +6737 +6519 +1991 +2974 +5339 +1614 +4366 +6332 +4183 +5651 +4116 +4057 +6751 + +6117 +5537 +4339 +5262 +5216 +3861 +1269 +6111 +4720 +3285 +3533 +4639 +1602 +2301 +1684 + +13962 +4475 +7421 +5710 + +1842 +13774 +7371 +5183 + +15576 +10011 +21697 + +1703 +6327 +1474 +2647 +2047 +1994 +5821 +5290 +5378 +3163 +6715 +1462 +5716 + +6500 +4135 +15482 +16325 +7377 + +4911 +3898 +7024 +4504 +8418 +3523 +7429 +1875 +1080 +3896 + +2364 +3213 +7568 +3554 +7065 +2300 +6145 +3674 +2579 + +6046 +2600 +3260 +1078 +4308 +5966 +4546 +2863 +4482 +5451 +5083 +1346 +6098 +5558 +3886 + +7594 +4850 +7782 +4683 +3996 +5939 +5193 +1411 +5856 +6158 +4151 + +9371 +7675 +4379 +4898 +6149 +7880 +4419 +3487 +3022 + +5027 +10030 +6295 +6916 +6102 +11647 + +2305 +7373 +2844 +5653 +2048 +2659 +7491 + +6571 +6102 +1435 +1680 +7241 +2643 +5597 +2855 +6189 +4513 +1702 +5352 + +3268 +4805 +3361 +4880 +2674 +7713 +7487 +8168 +1734 +7110 + +8153 +2756 +3447 +6789 +7761 +4724 +7481 +1835 +7373 +1573 + +6151 +6557 +6501 +1718 +4891 +4249 +1061 +2182 +6793 +5499 +5558 +5594 +6515 + +9371 +1943 +5818 +4018 +2133 +5379 +1396 +4527 +4334 + +27222 + +7807 +4918 +13254 +5437 +1057 +11915 + +50918 + +17389 +8573 +6769 +3223 + +6566 +7265 +7661 +2280 +2889 +6519 +7076 +5678 +4216 +3959 +5216 + +14059 +21822 + +16926 +5947 +15846 + +1421 +7117 +3267 +5141 +3504 +6315 +6485 +5849 +6779 +7299 +7087 +6235 + +5454 +6529 +6087 +8667 +7271 +6205 +3395 +7376 +4309 + +13097 +10266 +10587 +8406 +5973 + +31623 +19233 + +48107 + +4736 +1411 +3464 +2467 +3720 +5645 +6533 +1354 +4376 +5188 +1840 +1109 +2649 + +4624 +3867 +4932 +4705 +4752 +6636 +6935 +1763 +6683 +3182 +1279 + +4190 +1834 +4102 +2157 +1314 +4346 +4749 +4598 +2664 +5343 +1153 +2883 +2176 +2972 +5991 + +41319 + +10951 +3590 +3511 +10163 + +5379 +5046 +6185 +3099 +1479 +5463 +2003 +5895 +7133 +2941 +2377 +5604 + +1988 +3312 +4445 +6210 +4515 +1936 +1028 +3815 +7004 +6010 +3296 +6532 + +10653 +13005 +6246 +5002 +11939 +2610 + +2542 +1469 +4189 +5227 +2742 +3595 +1098 +1684 +1866 +2099 +3674 +3253 +1097 +4537 +5492 + +2503 +2386 +6625 +6206 +3044 +6910 +6005 +3726 +6556 +2116 +3373 +6039 + +5253 +2117 +7428 +2920 +3028 +6779 +5893 +2150 +5131 +3665 +4618 +6213 + +23441 +14459 + +3721 +7052 +5815 +5578 +7148 +2382 +4461 +5179 +3268 +7011 +4608 +5815 + +1426 +3853 +2734 +2087 +3561 +5430 +3453 +2662 +3850 +4482 +5771 +3764 +3698 +4567 +4285 + +6201 +23437 +21958 + +45685 + +1018 +4012 +2564 +1444 +6782 +2350 +5347 +2245 +6350 +1964 +6361 +3612 + +25442 +30894 + +7174 +6713 +7375 +1569 +6526 +5476 +6307 +1437 +3142 +1224 +2845 +4229 + +17039 +22539 +14263 + +5261 +6706 +18415 + +9354 + +2060 +5488 +5252 +4729 +1494 +1468 +1770 +6272 +4686 +1550 +2431 +3345 + +4333 +2475 +5919 +3201 +4253 +5595 +3763 +3299 +4557 +2466 +3908 +3506 +3666 +6102 +3271 + +2526 +6329 +4580 +6450 +3137 +3627 +2978 +1763 +3776 +4012 +3483 +6696 +6715 + +20837 + +6938 +4996 +2997 +1959 +4351 +2683 +6707 +6776 +7725 + +7454 +5422 +1719 +3273 +1263 +5817 +7068 +4047 +6591 +5467 + +25504 +13811 +1728 + +7332 +7843 +4698 +6364 +4560 +4973 +1579 +7189 +7706 +3898 +7777 + +2498 +3156 +2239 +5544 +5429 +5064 +3026 +3912 +5425 +2800 +2690 +3519 +1680 +4607 +5627 + +2848 +4523 +3083 +4742 +6058 +7632 +5695 +5896 +4150 + +7436 +7171 +6346 +6022 +3973 +7600 +6350 +2170 +2330 +2961 +2807 + +11194 +5672 +8861 +3820 +2318 +3608 +2535 + +4356 +1035 +2326 +2168 +4696 +3235 +3912 +3714 +2892 +1505 +2985 +3962 +5379 +5869 +2468 + +6176 +19825 +12752 +1789 + +6406 +4926 +2937 +5045 +6899 +6051 +6029 +4221 +6758 +3748 +2254 +5546 +6196 + +4197 +6095 +4615 +12118 +4239 +11880 + +5962 +6436 +2413 +1834 +3428 +2752 +3426 +2443 +2117 +4483 +3577 +2703 +4323 +2041 + +4511 +11096 +3091 +5826 +6323 +11881 +8688 + +3772 +5248 +3519 +1105 +5984 +1610 +5661 +1737 +2428 +2766 +1534 +4456 +1735 +1924 +4874 + +10428 +10725 +4803 +6867 +8574 +8520 +5612 +5855 + +28835 +18115 + +1549 +8536 +5806 +2597 +3777 +7724 +5803 +1500 +3754 + +17046 +19405 +3079 + +18363 +14060 +7675 +2603 + +2739 +2195 +1068 +4517 +5300 +4683 +6321 +6529 +3037 + +12958 +2464 +10649 +10001 +5557 +13397 + +6673 +3375 +9252 +9005 +3761 +9191 +7424 +7279 +8629 + +26298 +8367 + +3330 +4691 +6352 +7291 +2422 +1107 +3173 +5061 +4711 +4706 +4300 +3218 + +26181 + +2972 +2339 +9322 +1076 +2682 +4852 +7622 + +5641 +19288 +2918 +6314 + +3951 +2584 +5634 +1905 +5291 +1157 +3181 +1818 +3722 +4802 +4111 +2522 +3001 +4358 +2120 + +1077 +5533 +6400 +5381 +1006 +3449 +3155 +5997 +5918 +5556 +3050 +5280 +4295 +3936 + +9584 +8280 +6414 +2734 +7417 +4789 +6142 +8495 +8052 + +1327 +2087 +4527 +1098 +7191 +5222 +2375 +4037 +3780 +5426 +7144 +3261 + +37178 + +8043 +5217 +3272 +7191 +7990 +4697 +5140 +4541 +1169 +6205 + +6475 +12269 +8879 +18444 + +3075 +6082 +6593 +3094 +7802 +1862 +1994 + +10270 +7508 +14080 +5226 +11093 + +4093 +1046 +3565 +6243 +3054 +2416 +5708 +4547 +4317 +4341 +5802 +1029 +4809 + +12551 + +1105 +2947 +1508 +3953 +5390 +5139 +2045 +2040 +2028 +3621 +3594 +5765 + +4868 +5464 +4166 +1186 +1258 +5494 +1170 +2962 +4244 +2177 +5152 +4306 +5704 +2623 +5144 + +3933 +2777 +4077 +1728 +2543 +5292 +5055 +3498 +4288 +1910 +3631 +3266 +1959 +3334 +2893 + +12920 +36997 + +15084 +8596 +1619 +10189 +3402 + +5283 +2209 +4246 +1049 +7820 +1955 +1352 +6554 +7904 +6596 +3101 + +1732 +4551 +2842 +3485 +7432 +3587 +6443 +2499 +6964 +2325 +2001 +3936 + +2065 +11158 +3711 +7948 +1256 + +4646 +1220 +2075 +2517 +1612 +5728 +7408 +4255 +6139 +7265 +2205 + +20078 +12781 +15413 + +32493 + +12425 +5567 +1944 + +20490 +6224 +6355 + +2558 +3063 +4979 +4005 +4809 +1217 +6848 +6919 +6050 +1764 +1266 +1167 +1613 + +17719 +26741 + +5544 +13291 +2641 +12677 +14592 + +12413 +7876 +16123 + +8473 +9063 +2322 +6576 +12504 + +5141 +8613 +10753 +9990 +2696 +8297 +10125 + +8306 +6741 +8581 +6900 +4450 +1230 +6466 +1410 +6566 + +1735 +6150 +4168 +8651 +9338 +6301 +2437 +7349 +7270 + +5556 +5479 +4120 +2487 +4016 +5148 +4606 +3867 +5898 +5437 +3614 +2078 +2827 +5082 +4730 + +5361 +2506 +6122 +8706 +4328 +3030 +5801 +5956 +6575 +3166 + +5822 +2501 +3165 +5617 +2996 +4302 +4263 +5136 +6668 +3181 +1277 +1575 + +6963 +5403 +5751 +4803 +12025 +1235 +8890 + +2986 +3255 +5464 +3489 +3015 +6330 +5748 +2278 +5330 +1435 +5005 +3697 +1570 +6487 + +2381 +4178 +7190 +1615 +4813 +7485 +5712 +3673 +6748 +6428 + +6701 +15260 +16317 +3748 + +5146 +3783 +9166 +13869 +6908 + +7106 +9860 +2413 +6842 +8605 +11235 +4771 + +6745 +6142 +6972 +3538 +2115 +4595 +9610 + +7403 +7136 +2601 +6422 +2010 +2244 +8805 + diff --git a/2022/app/Main.hs b/2022/app/Main.hs index 65ae4a0..e1a3156 100644 --- a/2022/app/Main.hs +++ b/2022/app/Main.hs @@ -1,4 +1,7 @@ module Main where +import qualified Day1.Main as Day1 + main :: IO () -main = putStrLn "Hello, Haskell!" +main = do + Day1.main diff --git a/2022/cabal.config b/2022/cabal.config new file mode 100644 index 0000000..faf2bec --- /dev/null +++ b/2022/cabal.config @@ -0,0 +1,13 @@ +remote-repo-cache: /build/.cabal/packages +world-file: /build/.cabal/world +extra-prog-path: /build/.cabal/bin +build-summary: /build/.cabal/logs/build.log +remote-build-reporting: none +jobs: $ncpus +installdir: /build/.cabal/bin +haddock +init +install-dirs user +install-dirs global +program-locations +program-default-options diff --git a/2022/shell.nix b/2022/default.nix similarity index 61% rename from 2022/shell.nix rename to 2022/default.nix index fe1d8ba..6802d9a 100644 --- a/2022/shell.nix +++ b/2022/default.nix @@ -21,5 +21,16 @@ pkgs.stdenv.mkDerivation rec { if pkgs.stdenv.isLinux then "${pkgs.glibcLocales}/lib/locale/locale-archive" else ""; + src = ./.; + + # This currently doesn't work yet. + buildPhase = '' + export HOME=$TMP + mkdir -p $TMP/.cabal $out/bin + cp cabal.config $TMP/.cabal/config + cabal build + ln -s dist-newstyle/build/x86_64-linux/ghc-9.2.4/aoc2022-0.1.0.0/x/aoc2022/build/aoc2022/aoc2022 $out/bin/aoc2022 + ''; + }