How many?
Sunday Times Teaser 2502 – No Title
by H Bradley and C Higgins
Published September 5 2010 (link)
John and Pat were swimming at the pool. John started at the deep end at the same time as Pat started at the shallow end, each swimming lengths at their own steady speed. They passed each other on their first lengths and then passed each other again on their second lengths. It turned out that the length of the pool was a multiple of the distance between those first two passing points. John got out of the water after completing 48 lengths. At that moment Pat had also completed a whole number of lengths.
One Comment
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425262728293031323334353637383940414243from fractions import Fraction as RFfrom itertools import count# 0 ----------x----------------y------ l# Deep ================================== Shallow# John >> ----------x-----------------------# speed j y------# ----------x----------------------- <<< Pat# ---------------------------y speed p## Let r be the speed ratio be p / j; Pat completes N# lengths when John completes 48 so r = N / 48. Now# equate the times for Pat and John to reach x and y:## x / j = (l - x) / p ; (2.l - y) / j = (l + y) / p## (x/l) = 1 / (r + 1) ; (y/l) = (2.r - 1) / (r + 1)## (y - x) / l = 2.(r - 1) / (r + 1)## Let the pool length (l) be equal to K.(y - x), with# K an integer. So:## 2.K = (r + 1) / (r - 1) = (N + 48) / (N - 48)## N = 48 + 96 / (2.K - 1)## Since K and N are integers, 2.K - 1 must be an odd# divisor of 96 (2^5.3), which means that K = -1 and# N = 16 or K = 2 and N = 80; the N = 16 solution is# not valid since John would pass Pat for the second# time while Pat was still on their first length, not# their second as stated.for N in count(49):K, r = divmod(N + 48, 2 * (N - 48))if not r:x = RF(48, N + 48)y = 2 - 3 * xprint(f'Pat swims {N} lengths (x/l = {x}, y/l = {y}, (y - x)/l = {y - x}).')break