Created
June 18, 2017 14:55
-
-
Save yuradmt/fd672ee765f3aef2c0b281a170b2e93f to your computer and use it in GitHub Desktop.
puzzle solve: a/bc+d/fe+g/hi = 1 , each letter represents a digit 1-9
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
""" | |
find a solution for a/bc + d/fe + g/hi = 1 where each letter represents | |
a unique digit | |
""" | |
import itertools | |
import math | |
for perm in itertools.permutations([1, 2, 3, 4, 5, 6, 7, 8, 9]): | |
perm = [float(x) for x in perm] | |
sumex = perm[0] / (perm[1] * 10 + perm[2]) + \ | |
perm[3] / (perm[4] * 10 + perm[5]) + \ | |
perm[6] / (perm[7] * 10 + perm[8]) | |
if math.fabs(abs(sumex - 1.0)) < 0.0001: | |
print("Found permutation!") | |
perm = [int(x) for x in perm] | |
print("{}/{}{} + {}/{}{} + {}/{}{}".format(*perm)) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment