adventofcode-2021/1/depthcounter.hs

28 lines
710 B
Haskell
Raw Normal View History

2021-12-03 02:12:45 +00:00
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