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