Solve the following alphametic:
O/NE + T/WO + S/IX = NI/NE,
where
/ indicates division. As expected, TWO
is divisible by 2, SIX is divisible by 6,
and NINE is divisible by 9, but oddly
TEN is divisible by 7. Each different
letter represents a different digit, the
same letter represents the same digit,
and there are no leading zeros.
O NE T WO S IX NI NE
6 24 7 56 9 18 21 24
ONE TWO SIX NINE TEN
624 756 918 2124 742
6/24 + 7/56 + 9/18 = 21/24
1/4 + 1/8 + 1/2 = 7/8
------
from itertools import permutations
for perm in permutations([0,1,2,3,4,5,6,7,8,9]):
O = perm[0]
if O == 0:
continue
N = perm[1]
if N == 0:
continue
T = perm[2]
if T == 0:
continue
W = perm[3]
E = perm[4]
I = perm[5]
X = perm[6]
S = perm[7]
if S == 0:
continue
NE = 10*N + E
WO = 10*W + O
IX = 10*I + X
NI = 10*N + I
ONE = 100*O + 10*N + E
TWO = 100*T + 10*W + O
SIX = 100*S + 10*I + X
NINE = 1000*N + 100*I + 10*N + E
TEN = 100*T + 10*E + N
if O/NE + T/WO + S/IX != NI/NE:
continue
if TWO%2 != 0:
continue
if SIX%6 != 0:
continue
if NINE%9 != 0:
continue
if TEN%7 != 0:
continue
print(O/NE + T/WO + S/IX , NI/NE )
print(O,NE , T,WO , S,IX , NI,NE )
print(ONE, TWO, SIX, NINE, TEN)
|
Posted by Larry
on 2025-01-05 10:14:19 |