In this cryptarithm, each letter above the line represents a digit differing by 1 from the digit represented by the same letter below the line. For example, if A=3 above the line, then A=2 or A=4 below the line. All occurrences of a letter on the same side of a line represent the same digit. It is also known that there are total of five digits in the solution.
ADABA
+CACBA
------
DBABC
56505
+ 15105
----------
71610
Instead of calling the sum DBABC, I called it EFGHI and then let E be limited to D +/- 1, F be limited to B +/- 1 etc.
count = 0
for A in range(1,10):
for B in range(0,10):
if A==B:
continue
for C in range(1,10):
if A==C or B==C:
continue
for D in range(0,10):
if A==D or B==D or C==D:
continue
ADABA = 10000*A+1000*D+100*A+10*B+A
CACBA = 10000*C+1000*A+100*C+10*B+A
n = ADABA+CACBA
for E in range(D-1,D+2,2):
for F in range(B-1,B+2,2):
for G in range(A-1,A+2,2):
for H in range(B-1,B+2,2):
for I in range(C-1,C+2,2):
DBABC = 10000*E + 1000*F+100*G+ 10*H + I
if n == DBABC:
count += 1
print(ADABA, CACBA, n, DBABC)
print('done', count)
---
Output:
56505 15105 71610 71610
done 1
|
Posted by Larry
on 2019-11-18 20:32:56 |