In [2]:
def t_n(t):
n = 0
for i in t:
n *= 10
n += i
return n
t_n((1,2,3))
Out[2]:
In [3]:
from itertools import permutations, combinations
splits = list((i,j) for i, j in combinations(range(1,9), 2))
found = set()
for i in permutations(range(1,10)):
for f,t in splits:
a, b, c = t_n(i[:f]), t_n(i[f:t]), t_n(i[t:])
if a*b == c:
print('{}*{}={}'.format(a, b, c))
found.add(c)
In [4]:
sorted(found)
Out[4]:
In [5]:
sum(found)
Out[5]:
In [ ]: