13 lines
446 B
Haskell
13 lines
446 B
Haskell
loop :: Int -> [Int] -> Int -> Int
|
|
loop _ [] acc = acc
|
|
loop prev (one:two:three:rest) acc
|
|
| prev < sum = loop sum (two:three:rest) (acc + 1)
|
|
| otherwise = loop sum (two:three:rest) acc
|
|
where sum = one + two + three
|
|
-- ignore last numbers that don't fit into a three number window
|
|
loop _ _ acc = acc
|
|
|
|
main = interact $ solution . getInput
|
|
where solution input = show $ loop (head input) (tail input) 0
|
|
getInput = map read . words
|