### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,367)
- misc (4)
- project euler (2)
- puzzle (90)
- puzzle# (48)
- site news (58)
- tantalizer (94)
- teaser (7)

### Site Stats

- 233,122 hits

Programming Enigma Puzzles

16 October 2017

Posted by on **From New Scientist #2248, 22nd July 2000** [link]

Marge, April, May, June, Julia and Augusta have all celebrated their birthday today. They are all teenagers and with the exception of the one pair of twins their ages are all different.

Today, only Marge and April have ages which are prime numbers, but the sum of the ages of all the girls is also a prime number. On their birthday last year, only May and June had ages which were prime numbers, but again the sum of the ages of all the girls was a prime number. On their birthday two years before that, only May and Julia had ages which were prime numbers, but even then, the sum of the ages of all the girls was again a prime number.

How old is Augusta?

[enigma1092]

%d bloggers like this:

I wrote a program that just considers all possible assignments of ages to the girls, and it ran in 435ms.

The Python 3.6 program below, starts by looking for sequences of ages that sum to a prime number, and would also give a prime sum for the ages a year ago and three years ago. It runs in 98ms.

Run:[ @repl.it ]Solution:Augusta is 15.There is only one assignment of ages that satisfies the conditions of the problems:

In fact, there are only two sequences of ages that will allow the sums to be prime this year, last year and three years ago:

For both sequences the sum last year would be 83, and three years ago it would be 71. But the first of these sequences would give three prime ages three years ago.

Here is the problem expressed as a set of MiniZinc constraints.

I get an execution time of 195ms for the [[

`mzn-gecode -a`

]] solver.