Teaser 2454: [French registrations]
From The Sunday Times, 4th October 2009 [link]
On holiday in France, I spotted two French cars parked side by side. The last two digits of their registration numbers represent the départements in which they are registered. Viewing the cars from the front and juxtaposing those two département numbers, I saw a four-figure prime number; and on going around the back and doing the same, I saw a different prime number.
Furthermore, the average of the two département numbers was prime, as was half their difference.
What were the two département numbers?
This puzzle was originally published with no title.
[teaser2454]
Jim Randell 8:34 am on 27 February 2026 Permalink |
Fortunately there is only one possible answer to the puzzle for 2-digit numbers, and it turns out they are valid département numbers.
The following run file executes in 84ms. (Internal runtime of the generated code is 4.6ms).
Solution: The two département numbers are: 39 and 43.
39 is Jura. 43 is Haute-Loire.
3943 and 4339 are primes, as is the mean of the two département numbers (41), and half the difference (2).
LikeLike
Ruud 2:44 pm on 27 February 2026 Permalink |
Your code doesn’t seem to test whether the front and back numbers are different., which is in the text.
It doesn’t make a difference here, though.
LikeLike
Jim Randell 3:00 pm on 27 February 2026 Permalink |
@Ruud: If the numbers are the same, then half the difference is zero, which is not prime. So in any candidate solutions found the numbers will be different. And it turns out there is is only one candidate pair of (2 digit) numbers that works.
LikeLike
Ruud 4:53 pm on 27 February 2026 Permalink |
Yes, that makes sense.
LikeLike
Jim Randell 4:29 pm on 27 February 2026 Permalink |
Or using the prime sieve from the enigma.py library.
The following program has an internal runtime of just 713µs.
from enigma import (primes, div, printf) # consider the smaller (4-digit) prime for p in primes.between(0, 9999): # extract the two 2-digit numbers (a, b) = divmod(p, 100) # construct the larger 4-digit prime if not (a < b): continue q = 100 * b + a if not (q in primes and div(a + b, 2) in primes and div(b - a, 2) in primes): continue # output solution printf("{a} {b}")LikeLike
Ruud 2:42 pm on 27 February 2026 Permalink |
import istr istr.int_format("02") for dep0, dep1 in istr.product(range(100), repeat=2): if all(x.is_prime() for x in (dep0 | dep1, dep1 | dep0, (dep0 + dep1) / 2, abs(dep0 - dep1) / 2)) and dep0 != dep1: print(dep0, dep1)LikeLike
Ruud 5:19 pm on 27 February 2026 Permalink |
With a sieve (like @Jim Randell)
import istr istr.int_format("04") for n in istr.primes(10000): if all(x.is_prime() for x in (n[2:] | (n[:2]), (n[:2] + n[2:]) / 2, (n[2:] - n[:2]) / 2)) and n[:2] < n[2:]: print(n[:2], n[2:])LikeLike