projects
/
advent-of-code-23.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
f2c85a0
)
Simplified the interval calculations
author
Neil Smith
<NeilNjae@users.noreply.github.com>
Wed, 6 Dec 2023 11:45:43 +0000
(11:45 +0000)
committer
Neil Smith
<NeilNjae@users.noreply.github.com>
Wed, 6 Dec 2023 11:45:43 +0000
(11:45 +0000)
advent05/Main.hs
patch
|
blob
|
history
diff --git
a/advent05/Main.hs
b/advent05/Main.hs
index 5dab7c10137b0ab821b956ab50a43d9c2e5571b0..a01860c8d67e8fa2899637e371a6227e05d7727f 100644
(file)
--- a/
advent05/Main.hs
+++ b/
advent05/Main.hs
@@
-49,10
+49,11
@@
followRequirements almanac (Requirement name vals) =
useRule :: Rule -> Interval -> ([Interval], [Interval], [Rule])
useRule (Rule (Iv rl rh) d) (Iv xl xh) = (newResults, newVals, newRules)
where newResults =
useRule :: Rule -> Interval -> ([Interval], [Interval], [Rule])
useRule (Rule (Iv rl rh) d) (Iv xl xh) = (newResults, newVals, newRules)
where newResults =
-
filter legalInterval [ Iv (min xl rl) (min xh (rl - 1)
) -- input below rule
+
filter legalInterval [ Iv xl (rl - 1
) -- input below rule
, Iv ((max xl rl) + d) ((min xh rh) + d)] -- input within rule
, Iv ((max xl rl) + d) ((min xh rh) + d)] -- input within rule
- newVals = filter legalInterval [Iv (max xl (rh + 1)) (max xh rh)] -- input above rule
- newRules = filter legalRule [Rule (Iv (max (xh + 1) rl) (max xh rh)) d] -- rule above input
+ newVals = filter legalInterval [Iv (rh + 1) xh] -- input above rule
+ newRules = filter legalRule [Rule (Iv (xh + 1) rh) d] -- rule above input
+
useRules :: [Rule] -> [Interval] -> [Interval]
useRules [] vals = vals
useRules :: [Rule] -> [Interval] -> [Interval]
useRules [] vals = vals