Sunday Times Teaser 2591 – Shilly Shally
by Danny Roth
Published: 20 May 2012 (link)
George and Martha are running a holiday camp and their four daughters are staying there. To keep the peace they have been given chalets in different areas. Amelia’s chalet number is between 1 and 99, Bertha’s is between 100 and 199, Caroline’s between 200 and 299, and Dorothy’s between 300 and 399.
George commented that the difference between any two of the four chalet numbers is either a square or a cube. Martha added that the same could be said for the sum of the chalet numbers of the three youngest daughters.
Who is the eldest daughter and what is her chalet number?
One Comment
Leave one →
-
Brian Gladman permalink123456789101112131415161718192021222324252627282930313233fs = 'The oldest daughter is {} and her chalet number is {} {}.'# a set of squares and cubes less than 1000sc = set((x ** 2 for x in range(31))) | set((x ** 3 for x in range(10)))# check possible lowest chalet numberfor a in range(1, 100):# the next chalet number must differ from the# first by a perfect square or a perfect cubefor bma in sc:b = a + bmaif 100 <= b < 200:# the same for the third but it must also differ from the# second by either a perfect square or a perfect cubefor cma in sc:c = a + cmaif 200 <= c < 300 and c - b in sc:# and the fourth but it must also differ from the second and# the third by either a perfect square or a perfect cubefor dma in sc:d = a + dmaif 300 <= d < 400 and set((d - b, d - c)) < sc:# the four chalet numbers and their sumt = (a, b, c, d)sum_t = sum(t)# now find chalet numbers that when removed# from this sum leave a perfect square or a# perfect cubev = [x for x in t if sum_t - x in sc]if v:print(fs.format('ABCD'[t.index(v[0])], v[0], t))