X-Git-Url: https://git.njae.me.uk/?p=advent-of-code-20.git;a=blobdiff_plain;f=advent09%2Fsrc%2Fadvent09.hs;h=0fd8dbf97b909d76431224b9a177aaab7d66db11;hp=d1c32d45e909110c5d3815551af76760394eb3e0;hb=a8fa6a2019e66caa9f626b9fe942887040301e07;hpb=fb79b0c5e699d81d19698d34b72e5151fcfcf0ef diff --git a/advent09/src/advent09.hs b/advent09/src/advent09.hs index d1c32d4..0fd8dbf 100644 --- a/advent09/src/advent09.hs +++ b/advent09/src/advent09.hs @@ -9,7 +9,6 @@ main = let firstInvalid = part1 nums print firstInvalid print $ part2 firstInvalid nums - -- print $ head $ part2 nums part1 nums = fst $ head $ filter (not . valid) $ slidingWindow 25 nums @@ -20,7 +19,8 @@ valid (target, window) = not $ null [(x, y) | x <- window, y <- window, x + y == part2 target nums = (maximum section) + (minimum section) - where section = head $ filter (sumsToTarget target) $ subStrings nums + where section = head $ filter (sumsToTarget target) $ subStrings smallNums + smallNums = dropWhileEnd (>= target) nums -- subStrings :: [a] -> [[a]] subStrings = (concatMap inits) . tails