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?



One response 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}")

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

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: