aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2021-12-01 13:55:48 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2021-12-01 14:05:07 +0200
commit2b1b80f1a16da78350c57ac9cbbf67ba21856f79 (patch)
treefc98db1c0eeda9ef17f0465e4ef2336b5390ae43
parent81d288abb85f53c7852a0ab8d0c690786b7807c4 (diff)
Clean up day01
-rw-r--r--day01/main.hs25
1 files changed, 9 insertions, 16 deletions
diff --git a/day01/main.hs b/day01/main.hs
index e4dbb1b..95c5e4b 100644
--- a/day01/main.hs
+++ b/day01/main.hs
@@ -6,26 +6,19 @@ diff :: [Int] -> [Int]
diff [] = []
diff xs = zipWith (-) (tail xs) xs
-e1 :: [Int] -> IO ()
-e1 ints = do
- let result = ints $> diff .> filter (> 0) .> length
- print result
+e1 :: [Int] -> Int
+e1 = diff .> filter (> 0) .> length
-e2 :: [Int] -> IO ()
-e2 ints = do
- let result =
- zip3 ints (tail ints) (tail (tail ints))
- $> map (\(x, y, z) -> x + y + z)
- .> diff
- .> filter (> 0)
- .> length
-
- print result
+e2 :: [Int] -> Int
+e2 ints =
+ zip3 ints (tail ints) (tail $ tail ints)
+ $> map (\(x, y, z) -> x + y + z)
+ .> e1
main :: IO ()
main =
do
contents <- getContents
let ints = map read (lines contents)
- e1 ints
- e2 ints
+ e1 ints $> print
+ e2 ints $> print