Insert your code into triples_1.py so as to find all triples of positive integers (i,j,k) such that i, j and k are
two digit numbers, no digit occurs more than once in i, j and k,
and the set of digits that occur in i, j or k is equal to
the set of digits that occur in the product of i, j and k.
If you are stuck, but only when you are stuck, then use >triples_1_scaffold_1.py. If you are still stuck, but only when you are still stuck, then use triples_1_scaffold_2.py.
思路:
ijk==(i//10)100_000+(i%10)10_000+(j//10)1_000+(j%10)100+(k//10)*10+k%10
#马丁解法
max_k=98
max_j=87
max_i=76
min_i=10
for i in range(min_i,max_i+1):
i_digits={i//10,i%10}
if len(i_digits)!=2:
continue
for j in range(i+1,max_j+1):
i_j_digits=i_digits.union((j//10,j%10))
if len(i_j_digits)!=4:
continue
for k in range(j+1,max_k+1):
i_j_k_digits=i_j_digits.union((k//10,k%10))
if len(i_j_k_digits)!=6:
continue
product=i*j*k
if product>=1_000_000:
break
if set(int(i) for i in str(product))==i_j_k_digits:
print(f'{i} x {j} x {k} = {product} is a solution.')
网友评论