Books · Solving Puzzles through Mathematical Programming
Chapter 13
The Prime Circle
A prime circle of order is an arrangement of the integers around a circle such that every adjacent pair sums to a prime. For the arrangement is a prime circle: the four adjacent sums are , all prime. For , the circle has adjacent sums — again, all prime. One is naturally led to ask for which a prime circle exists.
The problem was proposed by Antonio Filz in the Journal of Recreational Mathematics in . For , a simple parity argument shows that any prime circle must alternate even and odd numbers. Indeed, the only even prime is , and two adjacent numbers in the circle can sum to only if they are both equal to , which is forbidden (they are distinct). Hence every adjacent sum is odd, so one addend is even and the other odd; the circle alternates. Since the set contains exactly evens and odds, alternation is possible whenever the circle length is even, which it always is. The parity argument rules out no ; the actual question is whether the sums can all be prime, given that the evens and odds must interleave.
Filz conjectured that a prime circle exists for every . The conjecture remains open, but the evidence is substantial: the counts recorded in OEIS sequence A051252 are nonzero for every order checked, a range that Tilley and Wagon extended to , and recent work on the Hamiltonicity of prime-sum graphs has proved that prime circles exist for infinitely many even orders. No infinite family of counterexamples is known, and no full proof of existence is known either.
The programming model
The encoding is particularly compact. For each position on the circle, let be the integer occupying that position. The constraints are:
Distinctness
Adjacent-sum primality
Precompute the list of pairs with , , and prime. For every pair of adjacent positions impose the table constraint
Symmetry breaking
A circle and its rotation are the same arrangement; likewise a circle and its reflection. The two symmetries have orders and respectively, giving a -fold orbit. Break the rotational symmetry by pinning ; break the reflection by requiring .
A solver in fifteen lines
from ortools.sat.python import cp_model
from sympy import isprime
def prime_circle(n):
N = 2 * n
pairs = [(a, b)
for a in range(1, N + 1)
for b in range(1, N + 1)
if a != b and isprime(a + b)]
m = cp_model.CpModel()
x = [m.NewIntVar(1, N, "") for _ in range(N)]
m.AddAllDifferent(x)
for i in range(N):
m.AddAllowedAssignments(
[x[i], x[(i + 1) % N]], pairs)
m.Add(x[0] == 1)
m.Add(x[1] < x[N - 1])
s = cp_model.CpSolver()
s.Solve(m)
return [s.Value(v) for v in x]
The solver returns one prime circle for each requested (a plain feasibility solve, so the particular circle found is not guaranteed to be the lexicographically smallest). Selected timings on a standard laptop: Figure 13.1 shows the prime circle of order found above; Figure 13.2 is the order- case.
Sources. Filz’s original question appears as Problem in the Journal of Recreational Mathematics, volume (), page , with solutions in volume (). Count data for prime circles (up to rotation and reflection) are listed as OEIS sequence A051252: the values for are , growing rapidly but not yet proven to be nonzero for all . The connection to Goldbach’s conjecture is sometimes asserted but is essentially superficial: if one could prove Goldbach, prime circles would not immediately follow, and the converse holds still less.