Created
April 6, 2020 08:47
-
-
Save AlbertVeli/b14713c9eac4f82f1ee3d9bba5d6805c to your computer and use it in GitHub Desktop.
Apple Banana Pineapple puzzle
This file contains 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
#!/usr/bin/env python3 | |
from z3 import * | |
a, b, p = Reals('a b p') | |
s = Solver() | |
s.add((a / (b + p)) + (b / (a + p)) + (p / (a + b)) == 4) | |
s.add(b != -p) | |
s.add(a != -p) | |
s.add(a != -b) | |
res = s.check() | |
if res == sat: | |
# print one solution (many might exist) | |
m = s.model() | |
print('apple =', m[a]) | |
print('banana =', m[b]) | |
print('pineapple =', m[p]) | |
else: | |
# unsat means no solution found | |
print(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment