X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=advent05%2FMain.hs;h=17e38bd384c0d4fcff8e75dc98f150e46939f035;hb=294c56539984358d1043c6c2bf7ae1f28eb88dff;hp=a01860c8d67e8fa2899637e371a6227e05d7727f;hpb=76763f234d95fa37bb0ebb4224d1e7dfa04dfbd9;p=advent-of-code-23.git diff --git a/advent05/Main.hs b/advent05/Main.hs index a01860c..17e38bd 100644 --- a/advent05/Main.hs +++ b/advent05/Main.hs @@ -49,10 +49,13 @@ 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 xl (rl - 1) -- input below rule - , Iv ((max xl rl) + d) ((min xh rh) + d)] -- input within rule - newVals = filter legalInterval [Iv (rh + 1) xh] -- input above rule - newRules = filter legalRule [Rule (Iv (xh + 1) rh) d] -- rule above input + 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 (rh + 1) xh] -- input above rule + newRules = filter legalRule + [Rule (Iv (xh + 1) rh) d] -- rule above input useRules :: [Rule] -> [Interval] -> [Interval]