diff options
author | Julien Dessaux | 2023-03-05 23:39:47 +0100 |
---|---|---|
committer | Julien Dessaux | 2023-03-05 23:47:17 +0100 |
commit | 2725c523ae3627cccd10650c69d8026e7a2f1d4b (patch) | |
tree | b19f916da8a5e8d2df7cdf8100c1cbcea780164a | |
parent | 2022-21 part 2 in js (diff) | |
download | advent-of-code-2725c523ae3627cccd10650c69d8026e7a2f1d4b.tar.gz advent-of-code-2725c523ae3627cccd10650c69d8026e7a2f1d4b.tar.bz2 advent-of-code-2725c523ae3627cccd10650c69d8026e7a2f1d4b.zip |
2022-01 in haskell
Diffstat (limited to '')
-rw-r--r-- | 2022/01/first.hs | 13 | ||||
-rw-r--r-- | 2022/01/second.hs | 13 |
2 files changed, 26 insertions, 0 deletions
diff --git a/2022/01/first.hs b/2022/01/first.hs new file mode 100644 index 0000000..300ca7d --- /dev/null +++ b/2022/01/first.hs @@ -0,0 +1,13 @@ +-- requires cabal install --lib split +module Main where + +import Data.List (sort) +import Data.List.Split (splitOn) + +parseAndSum :: String -> [Int] +parseAndSum = map (sum . map read . lines) . splitOn "\n\n" + +main :: IO () +main = do + input <- readFile "input" + print . head . reverse . sort $ parseAndSum input diff --git a/2022/01/second.hs b/2022/01/second.hs new file mode 100644 index 0000000..dedd4bc --- /dev/null +++ b/2022/01/second.hs @@ -0,0 +1,13 @@ +-- requires cabal install --lib split +module Main where + +import Data.List (sort) +import Data.List.Split (splitOn) + +parseAndSum :: String -> [Int] +parseAndSum = map (sum . map read . lines) . splitOn "\n\n" + +main :: IO () +main = do + input <- readFile "input" + print . sum . (take 3) . reverse . sort $ parseAndSum input |