# Enigmatic Code

Programming Enigma Puzzles

## Enigma 242: Sounds Greek

From New Scientist #1388, 15th December 1983 [link]

The three brothers Alpha, Beta and Gamma (who have different ages) get their sums consistently wrong. They all know their facts and do their calculations correctly, but just before they have to state any numerical answer they change it. One of the three brothers halves the number, one squares it, and the other reverses the number (so that 17 becomes 71, and 90 or 9 becomes 9).

I recently asked them their ages.

The eldest of the three whispered his age to the thinnest, who whispered it to Gamma, who whispered it to the youngest, who told me the answer was 27.

The next youngest of the three whispered his age to the tallest, who whispered the answer to Beta, who whispered it to the shortest, who told me the answer was 23.

Finally, the youngest whispered his age to the shortest, who whispered the answer to the thinnest, who whispered it to Alpha, who told me the answer was 16.

Describe the shortest brother (that is, name, age, and what he does to numbers).

It’s three years since I started the site and there are now 750 Enigma puzzles in the archive, all of them solved and almost all of them solved programatically. This puzzle means we have the first 242 puzzles from Enigma’s inception in February 1979 to December 1983 (there are 3 Christmas puzzles to add to complete 1983), and there’s very nearly a full 10 year archive of the most recent 507 puzzles from January 2004 to the end of Enigma in December 2013 (there are also 3 more puzzles from the start of 2004 required to complete this).

This leaves me with just over 1000 puzzles to source, publish and solve, so there are a good few years of Enigma puzzling left.

[enigma242]

### One response to “Enigma 242: Sounds Greek”

1. Jim Randell 3 December 2014 at 8:12 am

This Python program runs in 33ms.

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

# the inverse of the three afflictions
# (assume we are dealing with whole numbers)

# "one brother halves the number"
def half(x):
return 2 * x

# "one squares it"
def square(x):
return is_square(x)

# "one reverses the digits"
def reverse(x):
s = str(x)
if s[-1] == '0': return None
return int(s[::-1])

# compose the functions (in reverse order) given by the indices in args
# starting with value x
# ensure that no two neighbouring indices are the same
def compose(fn, x, args):
j = None
for i in reversed(args):
if j is not None and i == j: return None
x = fn[i](x)
if x is None: return None
j = i
return x

# indices for the brothers
brothers = (alpha, beta, gamma) = (0, 1, 2)

# assign the quirks (index -> quirk)
for q in permutations((half, square, reverse)):

# assign the ages (by index) (youngest, middle, eldest)
for a in permutations(brothers):

# assign the girths (by index) (thinnest, middle, fattest)
for g in permutations(brothers):

# compute the age of the eldest brother (statement 1)
Z = compose(q, 27, (a[2], g[0], gamma, a[0]))
if Z is None: continue

# assign the heights (by index) (shortest, middle, tallest)
for h in permutations(brothers):

# compute the age of the middle brother (statement 2)
Y = compose(q, 23, (a[1], h[2], beta, h[0]))
if Y is None or Y > Z: continue

# compute the age of the youngest brother (statement 3)
X = compose(q, 16, (a[0], h[0], g[0], alpha))
if X is None or X > Y: continue

printf("[ages={X},{Y},{Z}, q={q}, a={a}, g={g}, h={h}]", q=tuple(x.__name__ for x in q))

# who is the shortest?
s = h[0]
name = ('Alpha', 'Beta', 'Gamma')
printf("shortest={s}, age={a}, quirk={q}", s=name[s], a=(X, Y, Z)[a.index(s)], q=q[s].__name__)
```

Solution: Gamma is the shortest brother. His age is 16. He halves numbers.

We also know that Gamma is the middle by age, and is not the thinnest (so he is either middle by girth, or the fattest).

Alpha is the eldest at 21. He is the tallest, and is also not the thinnest (so if Gamma is the middle by girth he is the fattest, or vice versa). He squares numbers.

Beta is the youngest at 8. He is the thinnest, and middle by height. He reverses numbers.

The numbers that pass along the statements are:

1: 21 (Alpha squares) 441 (Beta reverses) 144 (Gamma halves) 72 (Beta reverses) 27.
2: 16 (Gamma halves) 8 (Alpha squares) 64 (Beta reverses) 46 (Gamma halves) 23.
3: 8 (Beta reverses) 8 (Gamma halves) 4 (Beta reverses) 4 (Alpha squares) 16.