Teaser 2530: [A day at the races]
From The Sunday Times, 20th March 2011 [link]
At the St Patrick’s Day races, Pat backed losers in each of the first three. Starting with £100, he bet a whole-number percentage of his money in the first race and a whole-number percentage of the remainder (but not a whole number of pounds) in the second. In the third, he bet a whole-number percentage of what was left, leaving a whole-number percentage of his £100. This final percentage was the sum of the three percentages he had bet and lost.
How much was lost on the third race?
This puzzle was originally published with no title.
[teaser2530]
Jim Randell 9:21 am on 27 June 2023 Permalink |
If the percentages bet are p1, p2, p3, and the remaining amounts after each bet it lost are r1, r2, r3, then:
So we can choose a value for r3, and split that into the three percentages (p1, p2, p3) and check the bets turn out as required.
And this approach does find the answer in a reasonable time, but it is not hugely fast.
This Python program runs in 347ms. (Internal runtime is 237ms).
Run: [ @replit ]
from enigma import (irange, decompose, printf) # generate possible (p1, p2, p3) percentage values def generate(): # consider the number of pounds remaining after the 3 bets for r in irange(3, 98): # this is equal to p1 + p2 + p3 yield from decompose(r, 3, increasing=0, sep=0, min_v=1) # consider values for p1, p2, p3 for (p1, p2, p3) in generate(): # bet 1, we lose p1 pounds r1 = 100 - p1 # bet 2, we lose not a whole number of pounds b2 = r1 * p2 # = (bet 2) * 100 if b2 % 100 == 0: continue r2 = 100 * r1 - b2 # = (remaining 2) * 100 # bet 3, we are left with (p1 + p2 + p3) pounds b3 = r2 * p3 # = (bet 3) * 100^2 r3 = 100 * r2 - b3 # = (remaining 3) * 100^2 if r3 != (p1 + p2 + p3) * 10000: continue # output solution printf( "p1={p1}% p2={p2}% p3={p3}% -> b1={b1:.2f} b2={b2:.2f} b3={b3:.2f}; r1={r1:.2f} r2={r2:.2f} r3={r3:.2f}", b1=float(p1), b2=(b2 * 0.01), b3=(b3 * 0.0001), r1=float(r1), r2=(r2 * 0.01), r3=(r3 * 0.0001), )Solution: £2.25 was bet (and lost) on the third race.
The scenario is:
For a faster program we can do a bit of analysis:
We can write (r1, r2, r3) in terms of (p1, p2, p3) to get:
Note that 5^4 divides the LHS, so it must divide the terms of the RHS, so one of them must be a multiple of 25 (i.e. 25, 50, 75), and another must also be a multiple of 5.
And this gives us a faster way to generate possible (p1, p2, p3) values.
This Python 3 program uses a different [[
generate()]] function, and runs in 61ms. (Internal runtime is 89µs).Run: [ @replit ]
from enigma import (irange, div, subsets, printf) # generate possible percentage values def generate(): # one of the values is a multiple of 25 for a in (25, 50, 75): # an another is a multiple of 5 for b in irange(5, 95 - a, step=5): c_ = div(10000 * (a + b + 100), 10000 + (100 - a) * (100 - b)) if c_ is None or not (c_ < 100): continue # return the values (in some order) yield from subsets((a, b, 100 - c_), size=len, select='mP') # consider values for p1, p2, p3 for (p1, p2, p3) in generate(): # bet 1, we lose p1 pounds r1 = 100 - p1 # bet 2, we lose not a whole number of pounds b2 = r1 * p2 # = (bet 2) * 100 if b2 % 100 == 0: continue r2 = 100 * r1 - b2 # = (remaining 2) * 100 # bet 3, we are left with (p1 + p2 + p3) pounds b3 = r2 * p3 # = (bet 3) * 100^2 r3 = 100 * r2 - b3 # = (remaining 3) * 100^2 if r3 != (p1 + p2 + p3) * 10000: continue # output solution printf( "p1={p1}% p2={p2}% p3={p3}% -> b1={b1:.2f} b2={b2:.2f} b3={b3:.2f}; r1={r1:.2f} r2={r2:.2f} r3={r3:.2f}", b1=float(p1), b2=(b2 * 0.01), b3=(b3 * 0.0001), r1=float(r1), r2=(r2 * 0.01), r3=(r3 * 0.0001), )In fact only one set of values (25, 25, 4) satisfies the analysis. And only with the 4% value for the final bet is the condition that the second amount bet is not a whole number of pounds satisfied.
LikeLike
Frits 7:08 pm on 27 June 2023 Permalink |
Manual solution:
Let the percentages NOT bet at each stage be p1, p2 and p3 and let the remainders after each stage be r1, r2 and r3 with the initial amount r0. Then r1 = r0.p1 / 100, r2 = r1.p2 / 100 and r3 = r2.p3 / 100 giving: p1 = 100.r1/r0 = 10000.r2/p2.r0 = 1000000.r3/p2.p3.r0 p1.p2.p3 = 10^6.r3/r0 Also: 100.r3/r0 = (100 - p1) + (100 - p2) + (100 - p3) Eliminating r3/r0 now allows p3 to be derived from p1 and p2: p3 = (300 - p1 - p2).10^4 / (10^4 + p1.p2) p1 * p2 * p3 - 10^4 * (300 - p1 - p2 - p3) = 0 p1 * p2 * p3 = (300 - p1 - p2 - p3) * 16 * 5^4 if p1, p2 and p3 are all multiples of 5 then (300 - p1 - p2 - p3) is also a multiple of 5 so p1 * p2 * p3 must be a multiple of 5^5 so we can conclude at least 2 out (p1, p2, p3) must be equal to 75, remaining percentage p* must be a multiple of 16 and (300 - p1 - p2 - p3) must be a multiple of 9 (3 * 3) (150 - p*) must be a multiple of 9 so p* mod 9 = 6 the only multiple of 16 and mod 9 = 6 out of 64, 80 and 96 is 96 so (p1, p2, p3) = (75, 75, 96) in any order p1 can't be 96 as 0.75 * 96 is a whole number p2 can't be 96 as 75 * 0.96 is the same whole number so (p1, p2, p3) = (75, 75, 96) in this order on the third race was lost: (3/4)^2 * 100 * (100 - 96) / 100 = 2.25 poundsLikeLike