aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-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