Simplified the interval calculations
[advent-of-code-23.git] / advent05 / Main.hs
index 002b8f58e802504820a20a9eeb585570a958e8d7..a01860c8d67e8fa2899637e371a6227e05d7727f 100644 (file)
@@ -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