Complete first day puzzles
This commit is contained in:
parent
90e4683d85
commit
45c118dcac
27
1/depthcounter.hs
Normal file
27
1/depthcounter.hs
Normal 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
2000
1/input.txt
Normal file
File diff suppressed because it is too large
Load diff
10
1/samplereport.txt
Normal file
10
1/samplereport.txt
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
199
|
||||||
|
200
|
||||||
|
208
|
||||||
|
210
|
||||||
|
200
|
||||||
|
207
|
||||||
|
240
|
||||||
|
269
|
||||||
|
260
|
||||||
|
263
|
Loading…
Reference in a new issue