From: Neil Smith Date: Tue, 15 Dec 2020 18:08:41 +0000 (+0000) Subject: Tweaks X-Git-Url: https://git.njae.me.uk/?p=advent-of-code-20.git;a=commitdiff_plain;h=a8fa6a2019e66caa9f626b9fe942887040301e07;ds=sidebyside Tweaks --- 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