# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1611: Three sisters

From New Scientist #2776, 4th September 2010 [link]

I have three aunts whose ages on their birthdays this year will each be a different prime. I would not dare to call them elderly, but at least one of them will be in her fifties. They were reminiscing that the last time their ages on their birthdays had all been prime in one year was 30 years ago, and on the occasion before that two of them had been in their teens.

“I wonder,” one of them said, “if we will be alive when it happens again?”

“I don’t see why not,” another replied, “for it will happen before any of us reaches 80.”

What will their ages be on their birthdays this year?

[enigma1611]

### 2 responses to “Enigma 1611: Three sisters”

1. jimrandell 30 December 2011 at 10:14 pm

The following Python program runs in 37ms.

```from enigma import irange, is_prime, printf
from itertools import combinations

# find primes below 80
primes = list(filter(is_prime, irange(3, 79, step=2)))

# 50's
fifties = set(irange(50, 59))

# teens
teens = set(irange(13, 19))

# consider sets of 3 primes
for now in combinations(primes, 3):
# at least one of them is in their 50's
if fifties.isdisjoint(now): continue
# thirty years ago the ages were also prime
minus30 = [x - 30 for x in now]
if not set(minus30).issubset(primes): continue
# and there are no years in between when all the ages were prime
if list(filter(lambda x: x.issubset(primes), [set(i - j for i in now) for j in range(1, 30)])): continue
# the time before that...
for i in irange(1, minus30[0] - 1):
before = [x - i for x in minus30]
if set(before).issubset(primes):
# ... two of them were in their teens
if len(teens.intersection(before)) != 2: continue
# and the next time it will happen before any of them are 80
for j in irange(1, 79 - now[2]):
nxt = [x + j for x in now]
if set(nxt).issubset(primes):
printf("now:{now} -30:{minus30} before:{before} next:{nxt}")
break
```

Solution: This year the aunts will be 59, 61 and 67.

2. geoffrounce 19 April 2018 at 11:52 am
```% A Solution in MiniZinc
include "globals.mzn";

set of int: primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47, 53, 59, 61, 67, 71, 73, 79};

% The three aunts' ages now
var 32..80: A;
var 32..80: B;
var 32..80: C;

% The number of years ago, greater than 30, when their ages were all prime
var 31..80: before30;

% The number of years to when it will happen next
var 3..50: after_now;

% The ages now are all different and prime
constraint A < B /\ B < C /\ A in primes /\ B in primes /\ C in primes;

% At least one of the aunts will be in her fifties this year
constraint card ({A, B, C} intersect {53, 59}) > 0;

% The aunts' ages can't be prime in the previous 29 years
constraint forall (i in 1..29) (not(A - i in primes) \/ not (B - i in primes)
\/ not(C - i in primes));

% Their ages 30 years ago were all prime
constraint A - 30 in primes /\ B - 30 in primes /\ C - 30 in primes;

% Their ages in a year greater than 30 years ago were all prime
constraint A - before30 in primes /\ B - before30 in primes /\ C - before30 in primes;

% Two of the aunts had been in their teens
constraint card ({A - before30, B - before30, C - before30} intersect {13, 17, 19}) = 2;

% There is a future occasion when all their ages will be prime and less than 80
constraint A + after_now in primes /\ B + after_now in primes /\ C + after_now in primes;
constraint C + after_now < 80;

solve satisfy;

output  ["\nPrime Ages now = " ++ show(A) ++ ", " ++ show(B) ++ ", " ++ show(C) ]
++ ["\nFuture Prime Ages = " ++ show(A + after_now) ++ ", " ++
show(B + after_now) ++ ", " ++  show(C + after_now) ];

% Prime Ages now = 59, 61, 67
% Future Prime Ages = 71, 73, 79
% Prime Ages 30 years ago = (29, 31, 37), and  48 years ago = (11, 13, 19)

```

This site uses Akismet to reduce spam. Learn how your comment data is processed.