Teaser 3301: Round the table
From The Sunday Times, 28th December 2025 [link] [link]
I recently attended a celebration with fewer than 100 family and friends. We sat round a large oval table with one seat for each person. I said to Liam that he could pick any seat, but it might be interesting to work out how many different arrangements were possible for people round the table. He replied: “I’ll leave that to you Grandad”, then (mischievously) added “but remember I always sit next to you and to Granny”.
The restriction that I must sit next to Liam divided the number of possible arrangements by a certain prime number. The further restriction that he must also be next to Granny caused further division by a prime number with a different number of digits.
What, in ascending order, are the number of people round the table and the two prime numbers?
This completes the archive of puzzles from 2025. There is now a complete archive of puzzles (and solutions!) from December 2009 onwards (plus a lot of earlier puzzles).
[teaser3301]
Jim Randell 5:41 am on 28 December 2025 Permalink |
With n people there are factorial(n) free arrangements (assignments of people to seats). (Or, if we only care about who is sitting next to who, and not about the absolute positions the number of free arrangements is factorial(n − 1) / 2 (i.e. is reduced by a factor of 2n)).
We can generate these by seating Liam, then Grandad, then Granny and then all the remaining (n − 3) guests.
After Liam has chosen his seat, for a free arrangement, Grandad has a choice of the remaining (n − 1) seats, but if we require Grandad to sit next to Liam, there is only a choice of 2 seats.
So this restriction reduces Grandad’s choice from (n − 1) to 2, so the number of arrangements is reduced by a factor of:
And this must be a prime number.
Similarly, if Granny had a free choice, she could could choose from (n − 2) seats, but if we require her to sit next to Liam, she must “choose” from only 1 seat.
This further reduces the number of arrangements by a factor of:
And this is also a prime number (with a different number of digits to p2).
If n is less than 100, then p2 must have 2 digits and p1 must have 1 digit. So there are only a few cases to consider, and a manual solution is straighforward.
This Python program starts from the total number of people n.
It runs in 69ms. (Internal runtime is 101µs).
from enigma import (irange, div, is_prime, ndigits, printf) # consider number of people around the table for n in irange(3, 99): # first restriction divides possibilities by a prime number p1 = div(n - 1, 2) if not is_prime(p1): continue # second restriction further divides possibilities by a prime number p2 = n - 2 if not is_prime(p2): continue # the primes have different numbers of digits if not (ndigits(p1) != ndigits(p2)): continue # output solution ss = sorted([n, p1, p2]) printf("n={n} -> p1={p1} p2={p2} {ss}")Or, shorter and faster, this Python program considers possible 1-digit prime values for p1.
It has an internal runtime of 54µs.
from enigma import (primes, printf) # p1 = (n - 1) / 2 is prime with fewer digits than p2 = n - 2 for p1 in primes.between(2, 9): n = 2 * p1 + 1 p2 = n - 2 if not (p2 > 9 and primes.is_prime(p2)): continue # output solution ss = [p1, p2, n] printf("n={n} -> p1={p1} p2={p2} {ss}")Solution: The numbers are: 7, 13, 15.
There are 15 people around the table.
So the total number of possible free arrangements is factorial(15) = 1307674368000.
But, requiring Grandad to sit next to Liam reduces Grandad’s choices from 14 to 2, so divides the number of possibilities by 7 (to give 186810624000 arrangements).
Further requiring Granny to also sit next to Liam reduces Granny’s choices from 13 to 1, so divides the number of possibilities by 13 (to give 14370048000 arrangements).
(If we only care about the relative seating arrangements (who sits next to who), then the number of arrangements is reduced by a factor of 2n = 30, but this does not affect the values of the divisions).
Manually:
p1 is a 1-digit prime, and p2 is a 2-digit prime such that:
and:
Considering 1-digit primes for p1 that are greater than 5:
LikeLike
Ruud 8:14 am on 28 December 2025 Permalink |
import peek import istr from math import factorial for n in range(3, 100): f1 = istr(factorial(n) / (n * 2 * factorial(n - 2))) f2 = istr(factorial(n - 2) / factorial(n - 3)) if f1.is_prime() and f2.is_prime() and len(f1) != len(f2): peek(sorted((n, f1, f2)))LikeLike
GeoffR 9:01 am on 30 December 2025 Permalink |
An AI solution, nicely commented by AI.
# ST 3301 by Perplexity AI import math def is_prime(num): if num < 2: return False for i in range(2, int(math.sqrt(num)) + 1): if num % i == 0: return False return True def digits(num): return len(str(num)) # Solve the teaser: n < 100 people around oval table (circular) # Total arrangements: (n-1)! # 1st restriction (Liam next to Grandad): divides by prime p1 with D1 digits # 2nd restriction (Liam also next to Granny): further divides # by prime p2 with D2 != D1 digits for n in range(3, 100): # At least 3 people (Grandad, Liam, Granny) # Fix Grandad's position to handle circular symmetry total = math.factorial(n - 1) # 1st restriction: Liam next to Grandad (2 choices for Liam's seat) restr1 = 2 * math.factorial(n - 2) div1 = total // restr1 # Should be integer prime if total % restr1 != 0 or not is_prime(div1): continue # 2nd restriction: Liam next to Grandad AND Granny # The three occupy 3 consecutive seats with Grandad fixed # 2 possible blocks (Liam-Granny or Granny-Liam to Grandad's sides) restr2 = 2 * math.factorial(n - 3) div2 = restr1 // restr2 # Further division from restr1 if restr1 % restr2 != 0 or not is_prime(div2): continue # Check different number of digits if digits(div1) != digits(div2): print(f"n={n}, First prime={div1} ({digits(div1)} digits)") print(f"Second prime={div2} ({digits(div2)} digits)")LikeLike