Sunday Times Teaser 2877 – Four Steadings and a Numeral
by Stephen Hogg
Published November 12 2017 (link)
Farmers Al, Bo, Cy and Di have different double-digit numbers of sheep kept in their respective steadings. Al has the fewest and his number of sheep is a certain fraction of Bo’s number of sheep. Also, Bo’s number of sheep is that same fraction of Cy’s number, and Cy’s number is that same fraction of Di’s.
If I told you the total of Bo’s number of sheep added to Cy’s, then you would be unable to work out all their numbers of sheep. Similarly, if instead I told you just Bo’s number of sheep, then you would be unable to work out all the other numbers.
What (in the order Al, Bo, Cy, Di) are their numbers of sheep?
One Comment
Leave one →
-
Brian Gladman permalink1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253from fractions import Fraction as RFfrom collections import defaultdict# generate four two-digit numbers in increasing order such# that the ratios between each number and its successor are# all the samedef generate():# select the largest number (D)for D in range(10, 100):# the next largest number (C) is less than Dfor C in range(10, D):# find the constant ratio from C and D and# compute A and Bf = RF(C, D)B = f * CA = f * B# if A has two digits and A and B are both integersif A >= 10 and A.denominator == B.denominator == 1:yield A.numerator, B.numerator, C, D# collect items in the sequence <seq> into groups with the# same result when the function <f> is applied to them;# find for such items those for which the function <g>,# when applied to an item does not give a unique resultdef filter(seq, f, g):d, e = defaultdict(list), defaultdict(set)for t in seq:k = f(t)d[k].append(t)e[k].add(g(t))m = set()for k, v in e.items():if len(v) > 1:m.update(d[k])return m# collect a list of possible sequenceslt1 = list(generate())# filter out those sequences for which the sum of B and C# identifies a unique result for (B, C)lt2 = filter(lt1, lambda t: t[1] + t[2], lambda t: (t[1], t[2]))# filter out those sequences for which B identifies# a unique result for (A, D)lt3 = filter(lt1, lambda t: t[1], lambda t: (t[0], t[3]))# the solution must be in both these groupssol, = lt2 & lt3fs = 'Al, Bo, Cy and Di respectively own {0}, {1}, {2} and {3} sheep.'print(fs.format(*sol))