Sunday Times Teaser 2850 – On Course
by Des MacHale
Published May 7 2017 (link)
Hackers-on-Sea golf course is designed by the great Jack Arnold. It is a par-seventy course and its eighteen holes are all par three, four or five. The numbers of all the par-five holes are primes, and the numbers of the par-four holes are odd.
Recently I only had time to play half the course and ideally my nine consecutive holes should be par thirty-five. However, there is no such collection of holes.
What are the numbers of the par-four holes?
One Comment
Leave one →
-
Brian Gladman permalink1234567891011121314151617181920212223242526272829303132333435363738394041from itertools import combinationsfrom number_theory import frobenius_solve, Primes# possible par 5 hole numberspar5 = set(Primes(18))# possible par 4 hole numberspar4 = set(range(1, 19, 2))# if the numbers of par 3, 4 and 5 holes are n3, n4 and n5 respectively,# we have 3.n3 + 4.n4 + 5.n5 == 70; this is a Frobenius problem for which# my number theory library has a solverfs = list(s for s in frobenius_solve([3, 4, 5], 70) if sum(s) == 18and s[1] <= len(par4) and s[2] <= len(par5))print(f'(n3, n4, n5): {fs}')# consider all possible sets of numbers for par 3, 4 and 5 holesfor n3, n4, n5 in fs:# a list for the par values of holes 1..18pv = [0] * 19# choose and set the par 5 holesfor p5 in combinations(par5, n5):for i in p5:pv[i] = 5# choose and set the par 4 holesfor p4 in combinations(par4.difference(p5), n4):for i in p4:pv[i] = 4# set the remainder as par 3 holesfor i in set(range(1, 19)).difference(p4 + p5):pv[i] = 3# there is no sequence of nine consecutive holes with a par of 35if not any(sum(pv[i:i+9]) == 35 for i in range(1, 11)):par = [[i for i, x in zip(range(19), pv) if x == k] for k in (3, 4, 5)]print('\nPar 3: {}\nPar 4: {}\nPar 5: {}\n'.format(*par))