advent-2021/1/solution.hs

23 lines
515 B
Haskell
Raw Normal View History

2021-12-02 11:35:13 +01:00
import Data.List
main :: IO ()
main = readFile "1/input.txt" >>= print . solve . parse . lines
parse :: [String] -> [Int]
parse = map read
solve :: [Int] -> (Int, Int)
solve input = (f input, g input)
where f = countInc
g = countInc . map sum . slide 3
countInc :: [Int] -> Int
countInc (a : rest @ (b : _))
| a < b = countInc rest + 1
| otherwise = countInc rest
countInc _ = 0
slide :: Int -> [Int] -> [[Int]]
slide _ [] = []
slide n list = take n list : slide n (tail list)