Solve:
FOR = I x WAS
where
W, A, and
S represent consecutive digits.
If it is required that W < A < S then there is a unique solution:
690 = 2 x 345
But if W,A,S can be in any order then there are 4 more solutions:
708 = 2 x 354
870 = 2 x 435
906 = 2 x 453
930 = 2 x 465
-----
triplets = [[i,i+1,i+2] for i in range(8)]
print('First Program')
from itertools import permutations
for t in triplets:
for perm in permutations(t):
WAS = 100*perm[0] + 10*perm[1] + perm[2]
for I in range(2,10):
if I in t:
continue
FOR = I * WAS
if FOR > 999:
continue
letters = str(FOR) + str(I) + str(WAS)
if len(letters) < 7:
continue
if len(letters) != len(set(letters)):
continue
print('{} = {} x {}'.format(FOR, I, WAS))
print('\n','Second Program')
for F in range(1,10):
for O in range(10):
if O in [F]:
continue
for R in range(10):
if R in [F,O]:
continue
for I in range(1,10):
if I in [F,O,R]:
continue
for W in range(1,10):
if W in [F,O,R,I]:
continue
for A in range(10):
if A in [F,O,R,I,W]:
continue
for S in range(10):
if S in [F,O,R,I,W,A]:
continue
if sorted([W,A,S]) not in triplets:
continue
FOR = 100*F + 10*O + R
WAS = 100*W + 10*A + S
if FOR == I * WAS:
print('{} = {} x {}'.format(FOR, I, WAS))
---- Output
First Program
690 = 2 x 345
708 = 2 x 354
870 = 2 x 435
906 = 2 x 453
930 = 2 x 465
Second Program
690 = 2 x 345
708 = 2 x 354
870 = 2 x 435
906 = 2 x 453
930 = 2 x 465
|
Posted by Larry
on 2024-05-16 11:22:13 |