X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=advent05%2FMain.hs;h=a01860c8d67e8fa2899637e371a6227e05d7727f;hb=76763f234d95fa37bb0ebb4224d1e7dfa04dfbd9;hp=002b8f58e802504820a20a9eeb585570a958e8d7;hpb=f8648c0ce55739dcadf19bbcdd56d5e48cd4f2e6;p=advent-of-code-23.git diff --git a/advent05/Main.hs b/advent05/Main.hs index 002b8f5..a01860c 100644 --- a/advent05/Main.hs +++ b/advent05/Main.hs @@ -49,10 +49,10 @@ 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] @@ -64,7 +64,6 @@ useRules (r@(Rule (Iv rl rh) _):rs) (v@(Iv xl xh):vs) | otherwise = newResults ++ (useRules (newRules ++ rs) (newVals ++ vs)) where (newResults, newVals, newRules) = useRule r v - legalInterval :: Interval -> Bool legalInterval (Iv l h) = l <= h