Teaser 2850: On course
From The Sunday Times, 7th May 2017 [link] [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?
[teaser2850]
Jim Randell 9:17 am on 13 January 2022 Permalink |
If n3, n4, n5 are the numbers of par 3, 4, 5 holes respectively we have:
We can treat the problem as a “money changing” puzzle, i.e. we want to make an amount of 70 using 18 coins of denominations 3, 4, 5.
The following Python program uses the [[
express()]] function from the enigma.py library. It runs in 50ms.Run: [ @replit ]
from enigma import (express, primes, irange, subsets, tuples, printf) # primes up to 18 primes = set(primes.between(1, 18)) # odd numbers up to 18 odds = set(irange(1, 18, step=2)) for (n3, n4, n5) in express(70, [3, 4, 5], min_q=1): if not (n3 + n4 + n5 == 18): continue # choose par 5 holes (prime) for p5s in subsets(primes, size=n5): # choose par 4 holes (odd) for p4s in subsets(odds.difference(p5s), size=n4): # the rest are par 3 par = [3] * 18 for k in p5s: par[k - 1] = 5 for k in p4s: par[k - 1] = 4 # no consecutive sequence of 9 holes sums to 35 if any(sum(t) == 35 for t in tuples(par, 9)): continue printf("p4s={p4s} p5s={p5s}; {par}")Solution: The par 4 holes are: 1, 9.
The par 5 holes are: 2, 3, 5, 7, 11, 13, 17.
We can use a more sophisticated “money changing” algorithm by using:
LikeLike