{-# LANGUAGE LambdaCase, MultiWayIf #-} module Main where import Data.Functor parse :: String -> [[Int]] parse = ((read <$>) . words <$>) . lines solve1 :: [[Int]] -> Int solve1 = let di a = all (\a' -> a' < 4 && not (a' <= 0)) a || all (\a' -> a' > -4 && not (a' >= 0)) a in sum . ((\a -> if di $ zipWith (flip (-)) a (tail a) then 1 else 0) <$>) solve2 :: [[Int]] -> Int solve2 = let r [] = [[]] r (r':rs) = rs:((r':) <$> r rs) in sum . ((\a -> if a > 0 then 1 else 0) . solve1 . r <$>) main :: IO () main = readFile "inputs/2" <&> parse >>= \i -> print (solve1 i) >> print (solve2 i)