Sunday Times Teaser 2763 – Golf Challenge
by Graham Smithers
Published: 6 September 2015 (link)
Mark and John played 18 holes of golf: the holes consisting of six each of par 3, par 4 and par 5. Each player finished the round in 72, consisting of six 3s, six 4s and six 5s. In fact each of them had six birdies (one under par), six on par, and six bogies (one over par). At no hole did the two players take the same number of strokes, and Mark beat John on ten of the holes.
How many of Mark’s winning holes were (a) on par 3 holes? (b) on par 4 holes? (c) on par 5 holes?
One Comment
Leave one →

Brian Gladman permalink12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576from itertools import permutations, combinations_with_replacement as cwrfrom operator import lt, eq, gt# return unique permutations of the sequence sdef unique_permutations(s):seen = set()for p in permutations(s):if p not in seen:seen.update([p])yield p# calculate the number of 3s, 4s and 5s and the number of birdies# pars and bogies scored in the six games (g)def results(g, par):return (tuple(sum(1 for x in g if x == i) for i in (3, 4, 5)),tuple(sum(1 for x in g if op(x, par)) for op in (lt, eq, gt)))# generate three tuples of six scores giving the possible scores for the# players over 18 holes, each with six 3s, 4s and 5s and each with six# birdies, pars and bogiesscores = []# six par three holes (5 not allowed because it is two over par)for p3 in cwr((3, 4), 6):# count the scores and the par resultsp3_345, p3_bpb = results(p3, 3)# six par five holes (3 not allowed because it is two under par)for p5 in cwr((4, 5), 6):# count the scores and the par resultsp5_345, p5_bpb = results(p5, 5)# the par four holes making up six of each scorep4_345 = tuple(6  (p3 + p5).count(x) for x in (3, 4, 5))if not all(0 <= x <= 6 for x in p4_345):continuep4 = tuple(sum(([i + 3] * p4_345[i] for i in range(3)), []))p4_bpb, _ = results(p4, 4)# overall we must have six birdies, six on par and six bogiesif all(x + y + z == 6 for x, y, z in zip(p3_bpb, p4_bpb, p5_bpb)):scores.append((p3, p4, p5))fs = 'Mark has {}, {} and {} wins on par 3, 4 and 5 holes respectively.'# for John's possible scores on par 3, 4 and 5 holesfor j3, j4, j5 in scores:# for Marks's possible scores on par 3, 4 and 5 holesfor _m3, _m4, _m5 in scores:# permute Mark's scores for par 3 holesfor m3 in unique_permutations(_m3):# and skip any arrangements containing drawsif any(x == y for x, y in zip(j3, m3)):continue# permute Mark's scores for par 4 holesfor m4 in unique_permutations(_m4):# and skip any arrangements containing drawsif any(x == y for x, y in zip(j4, m4)):continue# permute Mark's scores for par 5 holesfor m5 in unique_permutations(_m5):# and skip any arrangements containing drawsif any(x == y for x, y in zip(j5, m5)):continue# calculate how many holes Mark winswins = sum(1 for x, y in zip(j3 + j4 + j5, m3 + m4 + m5) if y < x)if wins == 10:# calculate and output the number of John's par 3, 4 and 5 winscnt = [[y < x for x, y in zip(*t)].count(True)for t in ((j3, m3), (j4, m4), (j5, m5))]print(fs.format(*cnt))print('Mark', m3, m4, m5)print('John', j3, j4, j5)