28 lines
710 B
Haskell
28 lines
710 B
Haskell
main = interact countTripleDepths
|
|
|
|
countDepths :: String -> String
|
|
countDepths depths =
|
|
let parse x = map (read) (lines x)
|
|
in
|
|
show (depthCounter (parse depths)) ++ "\n"
|
|
|
|
slide :: Int -> [a] -> [[a]]
|
|
slide _ [] = []
|
|
slide len list = (take len list):(slide len xs)
|
|
where (x:xs) = list
|
|
|
|
countTripleDepths :: String -> String
|
|
countTripleDepths depths =
|
|
let
|
|
parse x = map (read) (lines x)
|
|
deNoise x = map (sum) (slide 3 x)
|
|
in
|
|
show (depthCounter (deNoise (parse depths))) ++ "\n"
|
|
|
|
depthCounter :: (Integral a) => [a] -> a
|
|
depthCounter [] = 0
|
|
depthCounter [_] = 0
|
|
depthCounter (x:xs) = if x < head xs
|
|
then 1 + depthCounter xs
|
|
else 0 + depthCounter xs
|