# Enigmatic Code

Programming Enigma Puzzles

## Enigma 118: How many tens?

From New Scientist #1262, 16th July 1981 [link]

Long multiplication and long division were never too popular at school, unless of course they were made considerably easier by involving multiplication or division by 10. So this week’s exercise is a simple (?) calculation involving multiplication by TEN.

Usual letters-for-digits rules apply: a letter stands for a particular digit throughout, and different letters stand for different digits. The letters already shown can, of course, also be used to fill the blanks, but need not be.

What is ENIGMA?

[enigma118]

### 5 responses to “Enigma 118: How many tens?”

1. Jim Randell 18 August 2013 at 8:24 am

This Python program runs in 65ms.

```#        T E N
#  *     x x A
#  -----------
#        a a A  (= TEN * A)
#    b b b b    (= TEN * x2)
#  E A T c      (= TEN * x1)
#  -----------
#  E N I G M A

from itertools import permutations
from enigma import irange, nconcat, split, printf

# permissable digits
digits = set(irange(0, 9))

# choose digits for TEN
for (T, E, N) in permutations(digits, 3):
if T == 0: continue
TEN = nconcat(T, E, N)
d1 = digits.difference((T, E, N))
# and for A
for A in d1:
# check aaA
aaA = str(TEN * A)
if len(aaA) != 3: continue
if int(aaA[-1]) != A: continue
# choose xx
for xx in irange(100, 990, 10):
xxA = xx + A
# calculate ENIGMA
ENIGMA = str(TEN * xxA)
# check ENIGMA
if len(ENIGMA) != 6: continue
(e, n, I, G, M, a) = split(ENIGMA, int)
if not(e == E and n == N and a == A): continue
d2 = d1.difference((I, G, M))
if len(d2) != 4: continue
# calculate EATc
(x1, x2) = divmod(xx // 10, 10)
EATc = str(x1 * TEN)
# check EATc
if len(EATc) != 4: continue
(e, a, t, _) = split(EATc, int)
if not(e == E and a == A and t == T): continue
# check bbbb
if len(str(x2 * TEN)) != 4: continue

printf("ENIGMA={ENIGMA} [= {TEN} x {xxA}]")
```

Solution: ENIGMA = 163072 (= 416 × 392).

2. geoffrounce 22 August 2013 at 1:05 pm

A permutation solution also works, but takes a few seconds longer:

```# Capital letters only given in teaser
#    TEN
#    cdA
# ------
#    fhA  (n1)
#  ghjk0  (n2) - ends in zero
# EATq00  (n3) - ends in double zero
#-------
# ENIGMA

from itertools import permutations
for p in permutations(range(10),7):
t,e,n,a,i,g,m = p
if all (x !=0 for x in (t,e,n,a)):
enigma = a + m*10 + g*100 + i*1000 + n*10000 + e*100000
ten = n + e*10 + t*100
# c and d can be any integer between 1 and 9
for c in range(1,10):
for d in range(1,10):
cda = a + d*10 + c*100
# check 1st teaser condition for number n1
if ten * a < 1000 and (ten*a)%10 == a:
n1 = ten * a
n2 = d * ten *10
if n2 > 10000 and n2 <100000:
n3 = c * ten * 100
if n3 > 100000 and n3 < 1000000:
n3_str = str(n3)
# check 2nd teaser condition for number n3
if n3_str[0] == str(e) and n3_str[1] == str(a) \
and n3_str[2] == str(t):
if n1 + n2 + n3 == enigma:
print('ENIGMA = ',enigma, 'ie',ten, 'x', cda  )

```
3. Jim Randell 13 July 2014 at 12:50 pm

The problem can be recast as a long division sum, and then the SubstitutedDivision() solver from enigma.py can be used on it. This program runs in 99ms.

```from enigma import SubstitutedDivision

SubstitutedDivision(
'ENIGMA', 'TEN', '??A',
[('ENIG', 'EAT?', '???'), ('???M', '????', '??'), ('??A', '??A', '')]
).go()
```
4. prashanth kumar yb 9 January 2015 at 6:33 am

hi can u please explain the logic how to solve

• Jim Randell 9 January 2015 at 1:15 pm

The basic idea is to substitute the letters for (different) digits, so that the long multiplication sum makes sense. This means the assignment of letters has to be chosen such that the intermediate products also make sense. (The puzzle presents them in the opposite order I would have expected, which is why I re-wrote the sum in the initial comment of my first program).

You can do this with pencil and paper or write a computer program to do it for you. My programs try possible assignments of letters to digits, until it finds one that gives a sum that fits the diagram.