21 lines
552 B
Haskell
21 lines
552 B
Haskell
{-# LANGUAGE ScopedTypeVariables #-}
|
|
|
|
main = do
|
|
lines <- readFile "1.in"
|
|
putStrLn . show . solve . map (read :: String -> Integer) . words $ lines
|
|
where
|
|
solve = partB
|
|
|
|
-- solves all lines, returns a string
|
|
-- solve :: [string] -> a
|
|
partA = sum . map (boolToInt . cmpTuple) . double
|
|
where
|
|
double = zip <*> tail
|
|
cmpTuple = uncurry (<)
|
|
boolToInt = fromEnum
|
|
|
|
partB = partA . sumTuple3 . triple
|
|
where
|
|
triple x = zip3 x (tail x) (tail $ tail x)
|
|
sumTuple3 = map (\(x, y, z) -> x + y + z)
|