4 ms·
this was mine, brutey import itertools as it a = 'dog' b = 'food' c = 'tasty' letters = sorted(set(a+b+c)) for combo in it.permutatio
by RodericDay 11y ago
this was mine, brutey
import itertools as it
a = 'dog'
b = 'food'
c = 'tasty'
letters = sorted(set(a+b+c))
for combo in it.permutations('0123456789', len(letters)):
mapping = dict(zip(letters, combo))
if len(c) > max(len(a), len(b)) and mapping[c[0]] is '0':
continue
f = lambda string: int(''.join(map(mapping.get, string)))
n1, n2, n3 = map(f, [a, b, c])
if n1 + n2 == n3:
print( mapping )
print( n1, n2, n3 )
break
seems haskell friendly given all the mappings, but not in the way that the blogpost did it. but also not with that big nested loop either.