4
Day1/1.hs
Normal file
4
Day1/1.hs
Normal file
@@ -0,0 +1,4 @@
|
||||
import Lib (calories)
|
||||
|
||||
main :: IO ()
|
||||
main = print . maximum . calories =<< readFile "input"
|
6
Day1/2.hs
Normal file
6
Day1/2.hs
Normal file
@@ -0,0 +1,6 @@
|
||||
import Data.List (sortOn)
|
||||
import Data.Ord (Down (Down))
|
||||
import Lib (calories)
|
||||
|
||||
main :: IO ()
|
||||
main = print . sum . take 3 . sortOn Down . calories =<< readFile "input"
|
16
Day1/Lib.hs
Normal file
16
Day1/Lib.hs
Normal file
@@ -0,0 +1,16 @@
|
||||
module Lib (calories) where
|
||||
|
||||
calories :: String -> [Integer]
|
||||
calories input =
|
||||
map (sum . map read) $
|
||||
filter (not . null) $ split "" $ split '\n' input
|
||||
|
||||
split :: Eq a => a -> [a] -> [[a]]
|
||||
split del =
|
||||
foldr
|
||||
( \c (x : xs) ->
|
||||
if c == del
|
||||
then [] : x : xs
|
||||
else (c : x) : xs
|
||||
)
|
||||
[[]]
|
2237
Day1/input
Normal file
2237
Day1/input
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user