aboutsummaryrefslogtreecommitdiffstats
path: root/day01/main.hs
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2021-12-01 13:15:20 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2021-12-01 13:15:20 +0200
commit8c01338d1ce04103308628fad0038a890c2803fe (patch)
tree5dbbda72ce83677c6e7e35447f5e6ab937a9b3f2 /day01/main.hs
Day 01
Diffstat (limited to 'day01/main.hs')
-rw-r--r--day01/main.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/day01/main.hs b/day01/main.hs
new file mode 100644
index 0000000..e4dbb1b
--- /dev/null
+++ b/day01/main.hs
@@ -0,0 +1,31 @@
+module Main where
+
+import Utils
+
+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
+
+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
+
+main :: IO ()
+main =
+ do
+ contents <- getContents
+ let ints = map read (lines contents)
+ e1 ints
+ e2 ints