Sunday Times Teaser 2541 – Lotto Luck
by H Bradley and C Higgins
Published: 5 June 2011 (link)
Chris was lucky in the lotto, winning a whole number of pounds (under £5,000), which he shared with his five children. John got £1 more than a fifth of the total; Ciaran got £1 more than a fifth of the remainder. After Ciaran got his share, Fergal got £1 more than a fifth of the remainder, and after Fergal got his share, Brendan got £1 more than a fifth of what was left. After Brendan got his share, Chris gave Grainne £1 more than a fifth of what was left and kept the remainder (a whole number of pounds).
How much did Chris keep?
One Comment
Leave one →
-
Brian Gladman permalink123456789101112131415161718192021222324252627282930313233from itertools import countfrom fractions import Fraction as RF# It is faster to work the sequence in reverse from what# is left back to the original win.# convert a fraction to an integer but only if it is onefn = lambda x: x if x.denominator != 1 else x.numerator# try values for the final remainderfor rem in count():# a list for the intermediate remainders and the winr = [rem]# now run backwards through the five gifts, not# assuming that intermediate results are integerfor g in range(5):r.append(RF(5 * (r[-1] + 1), 4))# the final (win) must be an integerif r[-1].denominator == 1:# work out the gifted amountsr = r[::-1]gifts = map(fn, (a - b for a, b in zip(r, r[1:])))f, s, l = ', \xa3'.join(str(x) for x in gifts).rpartition(', ')gs = '\xa3{} and {}'.format(f, l)fs = 'He kept \xa3{} from a \xa3{} win with gifts of {}.'print(fs.format(rem, r[0], gs))break