Created
August 6, 2023 09:16
-
-
Save HACKE-RC/a758a8516d4a2ecf5172e53b76d0ae57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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