# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1325: Sum letters

From New Scientist #2484, 29th January 2005

I have just written down five different two-figure numbers:

•  my age
•  my house number
•  the sum of those first two numbers
•  the difference between those first two numbers
•  half of one of those first four numbers

However, I have written the names of the numbers in words rather than use figures. Surprisingly, each of the five numbers has precisely the same number of letters in its name.

What were the last three numbers?

[enigma1325]

### One response to “Enigma 1325: Sum letters”

1. Jim Randell 12 May 2014 at 8:14 am

This Python code uses the int2words() routine from the enigma.py library. It runs in 35ms.

```from collections import defaultdict
from itertools import permutations
from enigma import irange, int2words, printf

# compute the number of letters in 2-digit numbers
d = defaultdict(list)
for i in irange(10, 99):
s = int2words(i)
n = sum(1 for x in s if x.isalpha())
d[n].append(i)

# consider numbers with the same letter count
for (k, vs) in d.items():
# we need five different numbers altogether
if len(vs) < 5: continue
for (a, n) in permutations(vs, 2):
# the sum and difference should also have the same letter count
(s, d) = (a + n, abs(a - n))
if d in (a, n) or s not in vs or d not in vs: continue
# consider half one of the numbers
for h in (a, n, s, d):
(h, r) = divmod(h, 2)
if r: continue
if h in (a, n, s, d) or h not in vs: continue

printf("sum={s} difference={d} half={h} [age={a} number={n}]")
```

Solution: The last three numbers are: 86, 44 and 22.

The age and house number are 21 and 65, but we have no way to distinguish them, so we don’t know which is which. Their sum is 86, their difference is 44, and half of 44 is 22. “Twenty-one”, “sixty-five”, “eighty-six”, “forty-four” and “twenty-two” all have 9 letters.