aboutsummaryrefslogtreecommitdiff
path: root/2022
diff options
context:
space:
mode:
authorJulien Dessaux2023-03-05 23:39:47 +0100
committerJulien Dessaux2023-03-05 23:47:17 +0100
commit2725c523ae3627cccd10650c69d8026e7a2f1d4b (patch)
treeb19f916da8a5e8d2df7cdf8100c1cbcea780164a /2022
parent2022-21 part 2 in js (diff)
downloadadvent-of-code-2725c523ae3627cccd10650c69d8026e7a2f1d4b.tar.gz
advent-of-code-2725c523ae3627cccd10650c69d8026e7a2f1d4b.tar.bz2
advent-of-code-2725c523ae3627cccd10650c69d8026e7a2f1d4b.zip
2022-01 in haskell
Diffstat (limited to '2022')
-rw-r--r--2022/01/first.hs13
-rw-r--r--2022/01/second.hs13
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