Skip to content

Instantly share code, notes, and snippets.

@shinh
Created February 5, 2020 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinh/093ebf7e63aadf96b33e5a3e973d6124 to your computer and use it in GitHub Desktop.
Save shinh/093ebf7e63aadf96b33e5a3e973d6124 to your computer and use it in GitHub Desktop.
from z3 import *
x, y, a = Ints(['x', 'y', 'a'])
solver = Solver()
def r(x, n):
solver.add(x >= n)
solver.add(x < n * 10)
solver.add(y * 10 == x * a)
solver.add(((x % 10) * (a % 10)) % 10 == 0)
solver.add(((x % 10) * (a / 100)) % 10 == 6)
r(x, 10)
r(y, 1000)
r(a, 100)
r(x * (a / 100), 100)
r(x * (a / 10 % 10), 10)
r(x * (a % 10), 10)
r(y / 10 - x * (a / 100), 10)
r = solver.check()
if r == sat:
m = solver.model()
print(m[x], m[y], m[a])
else:
print('unsat')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment