# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1588: As easy as 1-2-3

From New Scientist #2753, 27th March 2010 [link]

Different letters stand for different digits and the same letter stands for the same digit in the multiplication sum shown above, where each dot can be any digit and leading digits cannot be zero.

If ONE, TWO and THREE are exactly divisible by 2 and 3, what number is THREE?

[enigma1588]

### 2 responses to “Enigma 1588: As easy as 1-2-3”

1. jimrandell 25 January 2012 at 7:15 pm

There are lots of ways of approaching this one.

This Python program runs in 35ms.

```from itertools import permutations
from enigma import irange, printf

# O, E must be even
# O, T cannot be zero

d = set(irange(0, 9))

for O in (2, 4, 6, 8):
for E in (0, 2, 4, 6, 8):
if O == E: continue
d1 = d.difference((O, E))
for N in d1:
if (O + N) % 10 != E: continue
ONE = O * 100 + N * 10 + E
if ONE % 3: continue

d2 = d1.difference((N,))
for (T, W) in permutations(d2, 2):
if T == 0: continue
TWO = T * 100 + W * 10 + O
if TWO % 3: continue

# ONE and TWO must be single digit multiples of some 3-digit number (A)
for b1 in irange(1, 9):
(A, r) = divmod(ONE, b1)
if r: continue
if not(99 < A < 1000): continue
(b2, r) = divmod(TWO, A)
if r: continue
if not(b2 < 10): continue

# and A * b3 must be 3-digit
for b3 in irange(1, 9):
if not(99 < A * b3 < 1000): continue

# and the total product must be THREE
THREE = A * (b3 * 100 + b2 * 10 + b1)
s = list(map(int, list(str(THREE))))
if not(len(s) == 5): continue
if not(s[0] == T and s[3] == s[4] == E): continue
if len(set((O, E, N, T, W, s[1], s[2]))) != 7: continue

printf("A={A} B={b3}{b2}{b1} ONE={ONE} TWO={TWO} THREE={THREE}")
```

Solution: THREE = 12744.

The multiplication sum is: 108 × 118 = 12744, giving ONE = 864 and TWO = 108.

• Jim Randell 16 March 2018 at 3:39 pm

Here’s a solution using the SubstitutedExpression() solver from the enigma.py library.

This run file executes in 108ms.

```#!/usr/bin/env python -m enigma -r

#      a b c
#  *   d e f
#  ---------
#      O N E
#    T W O
#  g h i
#  ---------
#  T H R E E

SubstitutedExpression

--symbols="EHNORTWabcdefghi"
--distinct="EHNORTW"