Sunday Times Teaser 2644 – Route Canal
by Peter G Chamberlain
A 70 mile canal trip is planned from the lock at Aytown to the lock at Beeswick with a stop at a pub next to a lock over half way along the route.
A list is created of the number of miles between Aytown and the pub, between the pub and Beeswick, and between adjacent locks.
A list is created of the number of miles between Aytown and the pub, between the pub and Beeswick, and between adjacent locks (where the longest is between the pub and the next lock towards Beeswick).
In the order visited, what are the numbers of miles between adjacent locks?
One Comment
Leave one →
-
brian gladman permalink12345678910111213141516171819202122232425262728293031323334353637383940414243# primes less than 70primes = [2, 3, 5, 7]primes += [x for x in range(11, 70, 2) if all(x % p for p in primes)]# locks: list of distances between locks# distances: distances from start to each lock# left: unused (prime) lock distances# pub_at: distance to the pubdef place(locks, distances, left, pub_at):if distances[-1] < 70:# place another lockfor nxt in left:# its distance from the startl = distances[-1] + nxt# check that its distance from all other locks# is prime whenever it is oddfor x in distances:if (l - x) % 2 and l - x not in primes:breakelse:# place more locksplace(locks + [nxt], distances + [l], left - set((nxt,)), pub_at)# if we have reached the destination via the pubelif distances[-1] == 70 and pub_at in distances:# the maximum distance between locks must be# immediately after the pubif locks[distances.index(pub_at)] == max(locks):fs = 'lock gaps {:s}, at {:s}, pub {:d}'print(fs.format(tuple(locks), tuple(distances), pub_at))for pub in primes:# the pub is over half way and its distances from the# start and the finish are both primeif pub > 35 and 70 - pub in primes:# primes for distances between adjacent locks - the maximum distance# between locks is less than half the total distancelock_primes = set(p for p in primes if p < 35) - set((pub, 70 - pub))# place the locksplace([], [0], lock_primes, pub)