projects
/
advent-of-code-20.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Done day 22
[advent-of-code-20.git]
/
advent09
/
src
/
advent09.hs
diff --git
a/advent09/src/advent09.hs
b/advent09/src/advent09.hs
index d1c32d45e909110c5d3815551af76760394eb3e0..0fd8dbf97b909d76431224b9a177aaab7d66db11 100644
(file)
--- 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
let firstInvalid = part1 nums
print firstInvalid
print $ part2 firstInvalid nums
- -- print $ head $ part2 nums
part1 nums = fst $ head $ filter (not . valid) $ slidingWindow 25 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)
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
-- subStrings :: [a] -> [[a]]
subStrings = (concatMap inits) . tails