From: Neil Smith Date: Wed, 6 Dec 2023 11:45:43 +0000 (+0000) Subject: Simplified the interval calculations X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=76763f234d95fa37bb0ebb4224d1e7dfa04dfbd9;p=advent-of-code-23.git Simplified the interval calculations --- diff --git a/advent05/Main.hs b/advent05/Main.hs index 5dab7c1..a01860c 100644 --- 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 = - 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 - 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