Guest User

Using a sledgehammer to kill a fly

a guest
Nov 19th, 2021
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. from z3 import *
  2.  
  3. # Define a boatload of integers
  4. a, b, c, k = Ints('a b c k')
  5. a2, b2, c2, k2 = Ints('a2 b2 c2 k2')
  6.  
  7. # Ask for a solution directly
  8. solve(And(
  9.     # Ensure positive ints
  10.     a > 0,
  11.     b > 0,
  12.     c > 0,
  13.     k > 0,
  14.     # Our equivalence on squares
  15.     a * a + 5 * k == b * b,
  16.     b * b + 5 * k == c * c,
  17.     # Make sure nothing better exists
  18.     Not(Exists([a2, b2, c2, k2], And(
  19.         b2 < b, # Alternatively change to whatever other conditions you want
  20.         a2 > 0,
  21.         b2 > 0,
  22.         c2 > 0,
  23.         k2 > 0,
  24.         a2 * a2 + 5 * k2 == b2 * b2,
  25.         b2 * b2 + 5 * k2 == c2 * c2
  26.     )))
  27. ))
Advertisement
Add Comment
Please, Sign In to add comment