Solve the following cryptarithm, in which none of the letters is zero.
AB/CD + EF/GHJ = A
Each of the letters represents a different digit, and each digit is a different letter.
5 7 1 2 9 6 3 8 4
AB/CD + EF/GHJ = A
57/12 + 96/384 = 5
4.75 + 0.25 = 5
--------
from itertools import permutations
for perm in permutations([1,2,3,4,5,6,7,8,9]):
A = perm[0]
B = perm[1]
C = perm[2]
D = perm[3]
E = perm[4]
F = perm[5]
G = perm[6]
H = perm[7]
J = perm[8]
if (10*A+B)/(10*C+D) + (10*E+F)/(100*G+10*H+J) == A:
print(A,B,C,D,E,F,G,H,J)
print('AB/CD + EF/GHJ = A')
print('{}{}/{}{} + {}{}/{}{}{} = {}'.format(A,B,C,D,E,F,G,H,J,A))
print((10*A+B)/(10*C+D) , ' + ', (10*E+F)/(100*G+10*H+J), '=', A)
|
Posted by Larry
on 2025-01-10 08:04:53 |