Skip to content

Commit

Permalink
update sbv
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Dec 14, 2024
1 parent 34017bd commit 2c33de3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
5 changes: 1 addition & 4 deletions solutions/solutions.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions solutions/src/2024/13.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ single ax x
-- <https://en.wikipedia.org/wiki/Diophantine_equation>
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
Expand Down

0 comments on commit 2c33de3

Please sign in to comment.