From The Sunday Times, 28th April 1974 [link]
A party of six racegoers arrived on the course with precisely £6 each with which to speculate. There were six races on the card and six runners in each race, so they decided to hold sweepstakes among themselves on each of the six races, the stake being £1 per race per person.
The runners in each race were numbered 1, 2, 3, 4, 5 and 6, and each of the racegoers drew one of these numbers out of a hat. Each player’s number remained the same throughout the six races. There were thus, in effect, six separate sweepstakes, the holder of the winning number drawing £6 on each race. To add a little interest to the proceedings it was arranged that the winner on any one of the races would be permitted to buy (at cost price of £1) one additional chance in one or more of the races subsequent to his win, from one of the other players. Only a player who had not yet had a win could sell his chance.
At the conclusion of the events it transpired that three players had made a net profit; the holder of No. 1 who won £4, the holder of No. 5 who won £1, and the holder of No. 4. The holder of No. 2 lost £3, and the holder of No. 6 lost £6.
Three winning chances were sold, but none of these by the holders of Nos 1, 4 and 5. The holder of No. 1 did not have any transaction with the holders of Nos 2 and 3. There were no dead-heats and no number appeared in the winner’s frame in consecutive races.
What, in order, were the numbers of the six winning horses?
This puzzle is included in the book The Sunday Times Book of Brain-Teasers: Book 2 (1981). The puzzle text above is taken from the book.
[teaser668]
Jim Randell 10:17 am on 19 May 2022 Permalink |
I am assuming that leading zeros are not allowed in the 6-figure account numbers.
The following Python program runs in 58ms. (Internal run time is 442µs).
Run: [ @replit ]
from enigma import (irange, dsum, is_cube, is_square, chain, div, printf) # generate possible other values for G def generate(E, fn): for d in irange(2, 9): G = fn(E, d) if G is None: continue # G has 6 digits if G < 100000: break if G > 999999: break # G is a perfect square if not is_square(G): continue # the sum of G's digits is a perfect cube if not is_cube(dsum(G)): continue # viable value yield (G, d) # E is a 6 digit cube for i in irange(47, 99): E = i**3 # and the sum of its digits is a perfect square if not is_square(dsum(E)): continue # look for another 6-digit multiple that is a multiple or divisor of E mul = lambda E, d: E * d for (G, d) in chain(generate(E, mul), generate(E, div)): # output solution printf("E={E} G={G} [d={d}]")Solution: The gas account number is 147456.
And the electricity account number is 884736 (= 6 × 147456).
LikeLike
Frits 7:39 pm on 19 May 2022 Permalink |
from enigma import SubstitutedExpression, dsum # the alphametic puzzle p = SubstitutedExpression( [ # The electricity account number is a perfect cube and # the sum of its digits is a perfect square "is_square(dsum(EL ** 3))", # six-figure number "99999 < EL ** 3 < 1000000", # one is a multiple of the other "(GAS ** 2) % (EL ** 3) == 0 or (EL ** 3) % (GAS ** 2) == 0", # two different six-figure numbers "EL ** 3 != GAS ** 2", # The gas account number is a perfect square and # the sum of its digits is a perfect cube "is_cube(dsum(GAS ** 2))", # six-figure number "99999 < GAS ** 2 < 1000000", ], answer="GAS ** 2", d2i=dict([(k, "EG") for k in range(0, 3)] + [(3, "E")]), distinct="", verbose=0, ) # print answers for (_, ans) in p.solve(): print(f"{ans}")LikeLike
GeoffR 4:31 pm on 20 May 2022 Permalink |
% A Solution in MiniZinc include "globals.mzn"; % Elec Account - six digits var 1..9:E; var 0..9:F; var 0..9:G; var 0..9:H; var 0..9:I; var 0..9:J; % Gas Account - six digits var 1..9:g; var 0..9:h; var 0..9:i; var 0..9:j; var 0..9:k; var 0..9:l; var 100000..999999:Elec == 100000*E + 10000*F + 1000*G + 100*H + 10*I + J; var 100000..999999:Gas == 100000*g + 10000*h + 1000*i + 100*j + 10*k + l; % Two different six-figure account numbers constraint Elec != Gas; % One account number is a multiple of the other constraint Elec mod Gas == 0 \/ Gas mod Elec == 0; % 6-digit squares and cubes set of int: sq6 = {n * n | n in 317..999}; set of int: cb6 = {n * n * n | n in 47..99}; % 2-digit squares and cubes < 54 (i.e. < 6 * 9) set of int: cb2 = {n * n * n | n in 2..3}; set of int: sq2 = {n * n | n in 2..7}; % Square/Cube constraints for both accounts constraint Elec in cb6 /\ (E + F + G + H + I + J) in sq2; constraint Gas in sq6 /\ (g + h + i + j + k + l) in cb2; solve satisfy; output[ "Gas Acc No. = " ++ show(Gas) ++ "\n" ++ "Elec Acc No. = " ++ show(Elec)]; % Gas Acc No. = 147456 % Elec Acc No. = 884736 % ---------- % ==========LikeLike
GeoffR 8:36 am on 24 February 2023 Permalink |
from enigma import nsplit, is_square, is_cube sq6 = [ x * x for x in range(316, 999) ] cb6 = [ y * y * y for y in range(46, 99) ] for elec in cb6: for gas in sq6: if elec > gas and elec % gas == 0 : a, b, c, d, e, f = nsplit(elec) # electrical account digits sum to a perfect square if is_square(a + b + c + d + e + f): g, h, i, j, k, l = nsplit(gas) # gas account digits sum to a perfect cube if is_cube(g + h + i + j + k + l): print(f"Electrical account number = {elec}") print(f"Gas account number = {gas}") break elif gas > elec and gas % elec == 0: A, B, C, D, E, F = nsplit(gas) # gas account digits sum to a perfect cube if is_cube(A + B + C + D + E + F): G, H, I, J, K, L = nsplit(elec) # electrical account digits sum to a perfect square if is_square(G + H + I + J + K + L): print(f"Electrical account number = {elec}") print(f"Gas account number = {gas}") # Electrical account number = 884736 # Gas account number = 147456LikeLike