diff --git a/solutions/solutions.cabal b/solutions/solutions.cabal index 0a8ed40..5f89b7d 100644 --- a/solutions/solutions.cabal +++ b/solutions/solutions.cabal @@ -861,7 +861,6 @@ executable sln_2021_24_sbv import: day main-is: 2021/24_sbv.hs build-depends: sbv, containers - buildable: False executable sln_2021_25 import: day @@ -1105,9 +1104,7 @@ executable sln_2023_23 executable sln_2023_24 import: day main-is: 2023/24.hs - build-depends: hmatrix, sbv ^>= 10.2 - if impl(ghc >= 9.8) - buildable: False + build-depends: hmatrix, sbv ^>= 11 executable sln_2023_25 import: day diff --git a/solutions/src/2024/13.hs b/solutions/src/2024/13.hs index f6838d4..67931e6 100644 --- a/solutions/src/2024/13.hs +++ b/solutions/src/2024/13.hs @@ -85,14 +85,14 @@ single ax x -- colinear' :: Integer -> Integer -> Integer -> Integer colinear' ax bx x - | let (d, e, f) = integerGcde ax bx - , (h, 0) <- x `quotRem` d -- target x is a multiple of the gcd of the two button +x - , let a = e * h -- prototypical (but potentially negative) solution - , let b = f * h -- prototypical (but potentially negative) solution - , let u = ax `quot` d - , let v = - (bx `quot` d) - , let klo = a `divCeil` v - , let khi = b `div` u + | (d, e, f) <- integerGcde ax bx + , (h, 0) <- x `quotRem` d -- target x is a multiple of the gcd of the two button +x + , a <- e * h -- prototypical (but potentially negative) solution + , b <- f * h -- prototypical (but potentially negative) solution + , u <- ax `quot` d + , v <- - (bx `quot` d) + , klo <- a `divCeil` v + , khi <- b `div` u , klo <= khi = minimum [3 * (a - k * v) + (b - k * u) | k <- [klo, khi]] -- the relation is linear so one of the extremes is the answer | otherwise = 0