day one :)
This commit is contained in:
commit
b1f6fc6ffc
|
@ -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
|
||||
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue