X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=advent05%2FMain.hs;fp=advent05%2FMain.hs;h=a01860c8d67e8fa2899637e371a6227e05d7727f;hb=76763f234d95fa37bb0ebb4224d1e7dfa04dfbd9;hp=5dab7c10137b0ab821b956ab50a43d9c2e5571b0;hpb=f2c85a0f3caf4338314da60dd2c7823a4dad626c;p=advent-of-code-23.git 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