Teaser 2958: Sudoku crossword
From The Sunday Times, 2nd June 2019 [link] [link]
George and Martha are doing a mathematical crossword. There is a 3×3 grid with the numbers 1 to 9 inclusive appearing once each. The clues are as follows:
Across:
top line: a prime number
middle line: a prime number
bottom line: a prime numberDown:
left column: a perfect square
middle column: a perfect square
right column: a prime numberAlthough you do not need to know this, one of the diagonal three-digit numbers is also prime.
What is the sum of the three “across” numbers?
[teaser2958]










Jim Randell 8:18 pm on 31 May 2019 Permalink |
We can solve this using the [[
SubstitutedExpression()]] solver from the enigma.py library.This run file executes in 180ms.
Run: [ @repl.it ]
Solution: The sum of the three across numbers is 1449.
The grid is:
The across numbers are: 283 (prime), 547 (prime), 619 (prime), and their sum is 1449.
The down numbers are: 256 (square), 841 (square), 379 (prime), and their sum is 1476.
The diagonals can be read (left to right) as 249 and 643, and the second of these is prime.
There are no further solutions if the digit 0 is not excluded.
LikeLike
GeoffR 8:43 am on 21 June 2019 Permalink |
% A Solution in MiniZinc include "globals.mzn"; % Grid % A B C % D E F % G H I var 1..9:A; var 1..9:B; var 1..9:C; var 1..9:D; var 1..9:E; var 1..9:F; var 1..9:G; var 1..9:H; var 1..9:I; constraint all_different ( [A,B,C,D,E,F,G,H,I]); % Rows var 100..999: ABC = 100*A + 10*B + C; var 100..999: DEF = 100*D + 10*E + F; var 100..999: GHI = 100*G + 10*H + I; % Columns var 100..999: ADG = 100*A + 10*D + G; var 100..999: BEH = 100*B + 10*E + H; var 100..999: CFI = 100*C + 10*F + I; predicate is_prime(var int: x) = x > 1 /\ forall(i in 2..1 + ceil(sqrt(int2float(ub(x))))) ((i < x) -> (x mod i > 0)); set of int: sq3 = {n*n | n in 10..31}; % Rows constraint is_prime(ABC) /\ is_prime(DEF) /\ is_prime(GHI); % Columns constraint ADG in sq3 /\ BEH in sq3 /\ is_prime(CFI); solve satisfy; output [ "Rows total is "++ show(ABC + DEF + GHI) ] ++ [ "\nRows are "++ show(ABC) ++ ", " ++ show(DEF) ++ " and " ++ show (GHI) ]; % Rows total is 1449 % Rows are 283, 547 and 619 % time elapsed: 0.02 s %---------- % ========== % Finished in 253msecLikeLike