Day thirteen corrected

This commit is contained in:
2024-12-14 00:02:37 +01:00
parent 7580dde5cc
commit 9629f55985

View File

@@ -37,7 +37,6 @@ task1 input = do
task2 :: String -> IO IntType
task2 input = do
print $ zip machines (map tryCalculate machines)
return $ sum bestPrices
where
bestPrices :: [IntType]
@@ -63,7 +62,7 @@ tryCalculate Machine{
} = let a = -(pY % bY - pX % bX) / (aX % bX - aY % bY)
an = numerator a
in case denominator a of
1 -> Just $ Vec2 an ((pX - an * aX) `div` bX)
1 -> fmap (Vec2 an) ((pX - an * aX) `safeDiv` bX)
_ -> Nothing
safeDiv :: IntType -> IntType -> Maybe IntType