1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from alphasum import AlphaSum # find solutions for the first sum c1 = AlphaSum(['ONE', 'ONE'], 'TWO') for s in c1.solve(): # check that ONE and TWO don't have digits in a consecutive set s1, s2 = set(s[c] for c in 'ONE'), set(s[c] for c in 'TWO') if all(max(x) - min(x) != len(x) - 1 for x in (s1, s2)): # ind solutions for the second sum that are consistent with the first c2 = AlphaSum(['ONE', 'FOUR'], 'FIVE', l2d=s) for t in c2.solve(): # check that FOUR and FIVE don't have digits in a consecutive set s3, s4 = set(t[c] for c in 'FOUR'), set(t[c] for c in 'FIVE') if all(max(x) - min(x) != len(x) - 1 for x in (s3, s4)): # output details of the two sums and FIFTEEN as a number print(c1.output()) print(c2.output()) print(f"\nFIFTEEN = {c2.substitute('FIFTEEN')}") |