Sunday Times Teaser 2550 – Cricket Averages
by Graham Smithers
Published: 7 August 2011 (link)
Playing for our local team, Sam and Oliver between them took 5 wickets in each innings, taking 5 wickets each overall. Sam’s averages (ie runs per wicket) were lower than Oliver’s in both innings, but overall Sam had the higher average. All six averages were single non-zero digits.
If you knew Sam’s overall average, it would then be possible to calculate the number of runs scored against Sam and against Oliver.
What were the total runs scored against a) Sam and b) Oliver?
One Comment
Leave one →
-
Brian Gladman permalink123456789101112131415161718192021222324252627282930313233343536373839404142from itertools import productfrom collections import defaultdictd = defaultdict(set)# Sam's wickets taken in the first inningsfor s1 in range(1, 5):# Oliver's wickets taken in the first innings and# Sam and Oliver's taken in the second inningso1, s2, o2 = 5 - s1, 5 - s1, s1# try Sam's single digit averages in the two inningsfor sav1, sav2 in product(range(1, 10), repeat=2):# calculate Sam's overall average which must be# a whole numbersav3, rem = divmod(sav1 * s1 + sav2 * s2, 5)if not rem:# now try Oliver's averages in the two innings# which are higher than Oliver'sfor oav1, oav2 in product(range(sav1 + 1, 10), range(sav2 + 1, 10)):# calculate Oliver's overall average which must be# a whole number less than Sam'soav3, rem = divmod(oav1 * o1 + oav2 * o2, 5)if not rem and oav3 < sav3:# now save the overall runs scored against Sam# and Oliver associated with Sam's averaged[sav3].add((5 * sav3, 5 * oav3))# now look for an Overall average for Sam that leads to a# unique answer for the runs scored against Sam and Oliverfor av in d.keys():score, *r = d[av]if not r:fs = ('The runs scored against Sam and Oliver are {} and {}'' respectively.')print(fs.format(*score))