Brainteaser 1771: Lottery logic
From The Sunday Times, 25th August 1996 [link]
For his weekly flutter on the National Lottery my friend has to select six of the numbers between 1 and 49 inclusive. Last week he wrote his numbers in numerical order and noticed something which he thought would interest me.
The first three numbers written in succession, with no gaps, formed a perfect square. The remaining three, similarly combined, formed another square. He suggested I try to deduce his six numbers.
Fortunately I knew his largest number was even and that he always chose one single-digit number.
Which numbers had he selected?
This puzzle is included in the book Brainteasers (2002). The puzzle text above is taken from the book.
[teaser1771]
Jim Randell 1:58 pm on 15 December 2019 Permalink |
This Python program runs in 74ms.
Run: [ @replit ]
from itertools import product from enigma import (irange, nsplit, printf) # consider 5- and 6- digit squares (n5s, n6s) = (list(), list()) for i in irange(102, 689): n = i * i # split the square into 3 2-digit numbers (a, b, c) = nsplit(n, 3, 100) # the numbers must be increasing, less than 50 if not (a < b < c < 50): continue if a < 10: # the first set has exactly one 1-digit number if not (b < 10): n5s.append((a, b, c)) else: # the second set ends with an even number if c % 2 == 0: n6s.append((a, b, c)) # choose two groups of three for (n5, n6) in product(n5s, n6s): # are the groups in order? if not (n5[-1] < n6[0]): continue # output the numbers printf("{s}", s=n5 + n6)Solution: The numbers chosen are: 2, 13, 16, 21, 34, 44.
We have: 21316 = 146², 213444 = 462².
LikeLike
GeoffR 10:21 am on 16 December 2019 Permalink |
% A Solution in MiniZinc include "globals.mzn"; 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; var 1..9:J; var 1..9:K; var 10..49:BC = 10*B + C; var 10..49:DE = 10*D + E; var 10..49:FG = 10*F + G; var 10..49:HI = 10*H + I; var 10..49:JK = 10*J + K; % Lottery numbers are A, BC, DE, FG, HI, and JK constraint all_different ([BC, DE, FG, HI, JK]); % He wrote his numbers in numerical order constraint increasing([BC, DE, FG, HI, JK]); % Largest lottery number was even constraint JK mod 2 == 0; % Two perfect squares are ABCDE and FGHIJK var 10000..99999: ABCDE = 10000*A + 1000*B + 100*C + 10*D + E; var 100000..999999: FGHIJK = 100000*F + 10000*G + 1000*H + 100*I + 10*J + K; predicate is_sq(var int: y) = let { var 1..ceil(sqrt(int2float(ub(y)))): z } in z*z = y; % Split the six lottery numbers into two perfect squares constraint is_sq(ABCDE) /\ is_sq(FGHIJK); solve satisfy; output [ "Six Lottery numbers were " ++ show(A) ++ ", " ++ show(BC) ++ ", " ++ show(DE) ++ ", " ++ show(FG) ++ ", " ++ show(HI) ++ " and " ++ show(JK) ]; % Six Lottery numbers were 2, 13, 16, 21, 34 and 44 % % time elapsed: 0.03 s % ---------- % ==========LikeLike
John Crabtree 4:39 pm on 18 December 2019 Permalink |
The second square must end in 44 (sq. root = 362 + 50x or 338 + 50x), 36 (sq. root = 344 + 50x or 356 + 50x), or 24 (sq. root = 332 + 50x or 318 + 50x). By use of a calculator, the second square = 213444
Then the first square must end in 16 (sq. root = 104 + 50x or 146 + 50x). Again by use of a calculator, the first square = 21316.
And so the six numbers are 2, 13, 16, 21, 34 and 44.
LikeLike