Skip to content

Instantly share code, notes, and snippets.

@HACKE-RC
Created August 6, 2023 09:16
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 HACKE-RC/a758a8516d4a2ecf5172e53b76d0ae57 to your computer and use it in GitHub Desktop.
Save HACKE-RC/a758a8516d4a2ecf5172e53b76d0ae57 to your computer and use it in GitHub Desktop.
from z3 import *
square = Int("square")
circle = Int("circle")
triangle = Int("triangle")
solver = Solver()
solver.add(square * square + circle == 16)
solver.add(triangle * triangle * triangle == 27)
solver.add(triangle * square == 6)
# sat stands for sastisfiable, meaning that the set of constraints are satisfiable
if solver.check() == sat:
m = solver.model()
# eval method returns the numbers with the type z3.z3.IntNumRef
# as_long method is used to convert that type to int
square_value = m.eval(square).as_long()
circle_value = m.eval(circle).as_long()
triangle_value = m.eval(triangle).as_long()
result = square_value * circle_value * triangle_value
print("The answer is: ", result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment