Sunday Times Teaser 2760 – Prime Location
by Andrew Skidmore
Published: 16 August 2015 (link)
I have a rectangular garden of area just over one hectare. It is divided exactly into three parts — a lawn, a flower bed, and a vegetable patch. Each of these three areas is a rightangled triangle with sides a whole numbers of metres in length. A fence runs along two adjacent sides of the rectangular garden. The length of the fence is a prime number of metres.
What are the dimensions of the rectangular garden?
One Comment
Leave one →

Brian Gladman permalink1234567891011121314151617181920212223242526272829303132333435363738394041424344454647from number_theory import divisor_pairs, is_primefs = 'The garden is {} by {} metres ({} square metres).'def is_square(x):t = int(x ** 0.5 + 0.5)return t if x == t ** 2 else None# Let the length of the sides of the garden be a and b;# let a point on b split it into two parts of length c# and d; join this point to the opposite corners with# lines of length e and f. It is easy to show that:## c / a = a / d = e / f > a^2 = c.d## a^2 + c^2 = e^2 a^2 + d^2 = f^2for a in range(100):# c and d are the divisor pairs of a^2for c, d in divisor_pairs(a * a):b = c + d# check that the two diagonals are integer, that# the area is a bit higher than 10000 and that# half the perimeter is a primeif all(is_square(a * a + x * x) for x in (c, d)):area = a * bif 10000 < area < 11000 and is_prime(a + b):print(fs.format(a, b, area))# An alternative layout is to join diagonal corners# with a line, split it at a point into two parts# (c and d) and join the point to one of the other# corners with a line e. Here we have:## (c + d)^2 = a^2 + b^2## c.(c + d) = b^2 d.(c + d) = a^2for a in range(100):for d, cpd in divisor_pairs(a * a):b = is_square((cpd  d) * cpd)if b and a < b and is_prime(a + b):area = a * bif 10000 < area < 11000:print(fs.format(a, b, area))