Teaser 3284: Cricket square
From The Sunday Times, 31st August 2025 [link] [link]
We recently played a thrilling cricket match against the league leaders. Each team had two innings alternately (our opponents going first) and the combined total of runs scored in each innings determined the winner. Curiously both our opponents’ scores were 3-digit squares, the six digits all being different. The total of those two scores was also a square.
After our first innings (in which we scored a 3-digit prime number of runs), we had a lead, but after their second innings we trailed by a 3-digit prime number (less than 250). The six digits in these two primes were all different. Our second innings score was also a 3-digit prime number but we lost the match by a prime number of runs.
How many runs did we score in our second innings?
[teaser3284]
Jim Randell 7:04 am on 31 August 2025 Permalink |
Here is a solution using the [[
SubstitutedExpression]] solver from the enigma.py library.This run file executes in 154ms. (Internal runtime of the generated code is 4.7ms).
Solution: In the second innings, the setters team scored 239 runs.
The opponents scores were 324 and 576 (both square numbers, and the sum is 900, also a square number), but we don’t know which order they were scored in.
The setters team scores 659 (a prime number) in their first innings (and so were in lead lead after their first innings, but behind by 241 (a prime number) after the opponents second innings.
In their second innings, the setters team scored 239 (a prime number), which gives them a total of 898, so they lost the game by 2 runs (a prime number).
LikeLike
Ruud 2:51 pm on 31 August 2025 Permalink |
import peek import istr for they1, they2 in istr.product((x for x in istr.range(100, 1000) if x.is_square()), repeat=2): if (they1 + they2).is_square() and (they1 | they2).all_distinct(): for us1, us2 in istr.product((x for x in istr.range(100, 1000) if x.is_prime()), repeat=2): if us1 > they1: score3 = they1 + they2 - us1 if score3.is_prime() and len(score3) == 3 and score3 < 250: if (they1 + they2 - us1 - us2).is_prime(): if (score3 | us1).all_distinct(): peek(they1, they2, us1, us2)LikeLike
GeoffR 8:48 am on 2 September 2025 Permalink |
As an exercise, this posting is formatted to PEP-8 or the Python Enhancement Proposal. It does seem to make code more organised and readable. I used Jim’s names for variables.
from enigma import is_prime # three digit primes primes = [n for n in range(101, 1000, 2) if is_prime(n)] # three digit squares sq3 = [x ** 2 for x in range(10, 32)] # squares up to 2000 sq34 = [x ** 2 for x in range(10, 44)] # opponents first score for ABC in sq3: A, B, C = (int(x) for x in str(ABC)) if len(set(str((ABC)))) == 3: # our first score for UVW in primes: if UVW <= ABC: continue U, V, W = (int(x) for x in str(UVW)) # opponents second score for DEF in sq3: if DEF == ABC or ABC + DEF not in sq34: continue # ABC and DEF combined have six different digits D, E, F = (int(x) for x in str(DEF)) if len(set((A, B, C, D, E, F))) != 6: continue # after second score if not (100 < (RST := ABC + DEF - UVW) < 250 and is_prime(RST)): continue # UVW and RST combined have six different digits R, S, T = (int(x) for x in str(RST)) if len(set((U, V, W, R, S, T ))) != 6: continue # our second score for XYZ in primes: # we lost the match by a prime number of runs if XYZ != UVW and is_prime(ABC + DEF - UVW - XYZ): print(f"Home team scores(1st and 2nd): {UVW} and {XYZ}.") print(f"Visiting team scores(1st and 2nd): {ABC} and {DEF}.") print()LikeLike