Teaser 2936: Multicoloured
From The Sunday Times, 30th December 2018 [link] [link]
George and Martha are selling wall-paper of various colours. By replacing letters with positive digits, they have devised the following multiplication problem:
RED × GREY = YELLOW
The N in GREEN is the remaining positive digit. The red wall-paper is sold only in squares, which is appropriate since RED is a perfect square.
What is the value of GREEN?
[teaser2936]
Jim Randell 7:47 am on 13 March 2019 Permalink |
We can use the [[
SubstitutedExpression()]] solver from the enigma.py library to solve the alphametic expressions directly.This run-file executes in 119ms.
Run: [ @repl.it ]
Solution: GREEN = 21668.
The [[
is_square(RED)]] condition is optional (in that there are no further solutions if it is omitted), but it verifies the statement of the problem, and also allows the run-file to execute a little faster (and is convenient when pursuing a manual solution).LikeLike
GeoffR 12:12 pm on 13 March 2019 Permalink |
% A solution in MinZinc include "globals.mzn"; var 1..9:R; var 1..9:E; var 1..9:D; var 1..9:G; var 1..9:Y; var 1..9:L; var 1..9:O; var 1..9:W; var 1..9:N; constraint all_different([R, E, D, G, Y, L, O, W, N]); var 100..999: RED = 100*R + 10*E + D; var 1000..9999: GREY = 1000*G + 100*R + 10*E + Y; var 100000..999999: YELLOW = 100000*Y + 10000*E + 1000*L + 100*L + 10*O + W; var 10000..99999: GREEN =10000*G + 1000*R + 110*E + N; set of int: sq3 = {n*n | n in 10..31}; constraint RED in sq3; constraint RED * GREY == YELLOW; solve satisfy; output [ "GREEN = " ++ show(GREEN) ++ "\n" ++ show(RED) ++ " X " ++ show(GREY) ++ " = " ++ show(YELLOW)]; % GREEN = 21668 % 169 X 2163 = 365547 % time elapsed: 0.02 sLikeLike