# Sunday Times Brain-Teaser 904 – The Six Ages

*by Victor Bryant*

#### From The Sunday Times, 18th November 1979 (link)

Problems concerning ages have always proved fruitful and entertaining exercises to both mathematicians and non-mathematicians. Trial and error methods, calculators and normal or esoteric mathematical techniques can all be deployed to find the correct solution. The most elegant or the most economical method is naturally the most commendable, but the correct solution, however obtained, is the desideratum.

Our problem concerns six men whose ages are within the range 21 to 89 and any two of them differ by at least 9. If we take the two digits comprising each of the ages of three of the men, and reverse them, we obtain the ages of the other three men.

What is more, if we take the sum of the ages of the first group, we find that it equals the sum of the ages of the second group of three.

Also the sum of the squares of the three ages of the first group equals the sum of the squares of the ages of the second group of three.

Finally, one of the ages in each group is exactly twice an age in the other group.

What are the ages of the six men (in increasing order)?

This teaser is interesting since, as it hints, there are many different ways of approaching it.

Here is my first attempt which runs in 25 milliseconds.

It soon occurred to me that there can be only one age in each decade and this led to this solution:

which runs in 15 milliseconds.

A third option is to use a constraint programming approach using MiniZinc accessed using Jim Randell’s >minizinc wrapper:

However, this does not compete on speed, running in 250 milliseconds.

Another solution using recursion. I’m not sure if this is any faster than the above solutions

Final shot!

Never say ‘never’ or ‘final shot’ for that matter

I’m not entirely satisfied with my method of generating three non-overlapping pairs of digits which has an efficiency of about 1/30. I couldn’t come up with a ‘manual’ but not empirical method before patience ran out.

Hi John,

Wow, four different versions! This one beats your previous speed record and is down to 2 milliseconds on my PC.

I am certainly not sure my own patience would have lasted this long!

Well, here’s a fifth with every milligram of fat sweated out.

Hi John,

Congratulations, it certainly holds the speed record – it is too fast to register on profile, which I normally use for ad hoc timing. I also noticed your earlier neat trick for reversing the two digits when you make two digit values. And we now have eight different versions in total.

Line 31 of my code would be more readable if it were

But this is less concise; has more keystrokes.