Enigmatic Code

Programming Enigma Puzzles

Enigma 938: Trios of primes

From New Scientist #2093, 2nd August 1997

Harry, Tom and I were trying to find sets of three two-digit prime numbers such that if we added any two numbers of the set together the answer was double a prime. Within each set the three prime numbers had to be different; but we each found that having created a set we could created a second set by changing just one number in our first set.

One of my two sets was the same as one of Harry’s sets and the other was the same as one of Tom’s; their other sets were different.

(1) What were my two sets?
(2) Which set might we have found whose three primes do not appear in any other set?

I don’t have a source image for the puzzle as originally published, but I believe the above text is correct.

[enigma938]

3 responses to “Enigma 938: Trios of primes”

1. Jim Randell 20 December 2021 at 10:04 am

This Python program runs in 56ms.

Run: [ @replit ]

from enigma import Primes, subsets, intersect, diff, printf

primes = Primes(100)

# find triples of different 2-digit primes such that any pair sum to
# double a prime
p3s = list()
for (a, b, c) in subsets(primes.irange(10, 99), size=3):
if all(t // 2 in primes for t in (a + b, a + c, b + c)):
p3s.append((a, b, c))

# we can now answer the second question
# which triple is disjoint from all other triples?
for t in p3s:
if all(len(intersect([t, t_])) == 0 for t_ in p3s if t_ != t):
printf("q2: {t}")

# find triples that have two primes in common with another triple
pairs = list()
for (t1, t2) in subsets(p3s, size=2):
if len(intersect([t1, t2])) == 2:
pairs.append((t1, t2))

# choose a pair for D
for D in pairs:
# choose pairs for H and T
for (H, T) in subsets(diff(pairs, [D]), size=2):
if D in H and D in T:
printf("q1: D={D} [H={H} T={T}]")

Solution: (1) The setters sets were (11, 23, 71) and (11, 23, 83); (2) The set disjoint from all others is (13, 61, 73).

2. GeoffR 21 December 2021 at 8:46 am

A programme/manual solution.
I defined a function for a primality test for three numbers – if the sum of any two (from three) primes, divisible by two, was prime. There were only seven groups of three primes, of which five were used in the answers.

from itertools import combinations
from enigma import Primes, is_prime

# list of 2-digit primes
pr = [x for x in Primes(100) if x > 10]

# # list for groups of three primes passing primality test
pr2 = []

# prime test for sum of any two primes divisible by 2
def chk_pr(x, y, z):
if (is_prime((x + y) // 2) and  is_prime((x + z) // 2)
and is_prime((y + z) // 2) ):
return True
return False

# find groups of three primes
for a, b, c in combinations(pr, 3):
if chk_pr(a, b, c):
pr2.append((a, b, c))

# print groups of 2-digit primes
print(pr2)
# [(11, 23, 71), (11, 23, 83), (11, 47, 71), (13, 61, 73),
# (17, 29, 89), (23, 59, 83), (29, 53, 89)]

# Prime groups apparent from above prime list :
# Dick  = (11, 23, 71), (11, 23, 83) - change 71 to 83
# Harry = (11, 23, 71), (11, 47, 71) - change 23 to 47
# Tom =   (11, 23, 83), (23, 59, 83) - change 11 to 59
# Three primes that do not appear in any set are (13, 61, 73)
# Groups (17, 29, 89) and (29, 53, 89) were unused.

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