diff --git a/day1.hs b/day1.hs index da0e479f1017b37976dd78d011ac026577ec1136..835a8bdbf8cee899bc2e1be44305952b8cb39909 100644 --- a/day1.hs +++ b/day1.hs @@ -4,6 +4,7 @@ module Main where main = do contents <- readFile "input-1" print (whichFloor contents) + print (part2 (lander contents)) santa '(' = 1 @@ -11,3 +12,12 @@ santa ')' = -1 santa _ = 0 whichFloor xs = sum (map santa xs) + +-- part two; take stuff out of list until we reach -1 +-- fold == reduce, mostly + +isPositive x = x >= 0 + +part2 x = length (takeWhile isPositive x) + +lander x = scanl (+) 0 (map santa x)