22 lines
515 B
Haskell
22 lines
515 B
Haskell
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)
|