Complete first day puzzles

This commit is contained in:
Tristan Daniël Maat 2021-12-03 02:12:45 +00:00
parent 90e4683d85
commit 45c118dcac
Signed by: tlater
GPG key ID: 49670FD774E43268
3 changed files with 2037 additions and 0 deletions

27
1/depthcounter.hs Normal file
View file

@ -0,0 +1,27 @@
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

2000
1/input.txt Normal file

File diff suppressed because it is too large Load diff

10
1/samplereport.txt Normal file
View file

@ -0,0 +1,10 @@
199
200
208
210
200
207
240
269
260
263