day one :)

This commit is contained in:
Your Name 2022-12-10 18:12:16 +01:00 committed by qvalentin
commit b1f6fc6ffc
Signed by: qvalentin
GPG Key ID: C979FA1EAFCABF1C
3 changed files with 2281 additions and 0 deletions

2255
elves.txt Normal file

File diff suppressed because it is too large Load Diff

14
one.hs Normal file
View File

@ -0,0 +1,14 @@
import Text.Read
f :: (Int,Int) -> Maybe Int -> (Int,Int)
f (max,current) (Just next) = (max,current+next)
f (currentMax,current) (Nothing) = (max currentMax current ,0)
result=fst $ foldl f (0,0) (map (readMaybe) $lines "1000\n2000\n3000\n\n4000\n1000\n\n1000")
compute input=fst $ foldl f (0,0) $ map (readMaybe) $lines input
main = do
content <- readFile "elves.txt"
putStrLn $ show $compute content

12
one2.hs Normal file
View File

@ -0,0 +1,12 @@
import Text.Read
import Data.List
f :: ([Int],Int) -> Maybe Int -> ([Int],Int)
f (max,current) (Just next) = (max,current+next)
f (currentMax,current) (Nothing) = (take 3 $ reverse $ sort (current:currentMax) ,0)
compute input=sum $fst $ foldl f ([0],0) $ map (readMaybe) $lines input
main = do
content <- readFile "elves.txt"
putStrLn $ show $compute content