Teaser 2717: Round the garden
From The Sunday Times, 19th October 2014 [link] [link]
George and Martha’s garden is a quadrilateral with each of its sides a whole number of metres in length. When Martha wrote down the lengths of the four sides together with the length of the perimeter, she noticed that overall these five numbers used each of the ten digits exactly once. Also, the lengths of the three longest sides of the garden were prime numbers. She told George, but he was unable to work out all the lengths until she also told him that no two of the four lengths differed by a prime number.
What are the four lengths?
[teaser2717]



Jim Randell 9:31 am on 14 February 2023 Permalink |
This Python program finds candidate sets of sides of the quadrilateral such that the three longest sides are prime, and together with the fourth side and the calculated perimeter each of the digits 0-9 is used exactly once.
We then check the candidate solutions for sets where no pair of lengths differ by a prime, and this gives a unique solution.
The following Python program runs in 62ms. (Internal runtime is 11ms).
Run: [ @replit ]
from enigma import (primes, nsplit, irange, empty, rev, subsets, sq, printf) # combine digits of <n> with existing digits <ds> # digits cannot be used more than once def digits(n, ds): ds = set(ds) for d in nsplit(n): if d in ds: return ds.add(d) return ds # find sets of numbers that between them and their sum use each of the # 10 digits exactly once such that the largest 3 numbers are prime. # return: ((a, b, c, d), s); where a < b < c < d, s = a + b + c + d def solve(ns=[], ds=empty): k = len(ns) # are we done? if k == 4: # calculate the sum of the numbers t = sum(ns) # which should bring the digits used to 10 ds_ = digits(t, ds) if ds_ is not None and len(ds_) == 10: yield (rev(ns), t) else: # first 3 numbers are primes, but final number is not necessarily a prime a = 1 b = (111 if k == 0 else ns[-1] - 1) nrange = (irange if k == 3 else primes.irange) for n in nrange(a, b): # check for new distinct digits ds_ = digits(n, ds) if ds_ is not None: yield from solve(ns + [n], ds_) # quadrilateral check def is_quad(ss): if len(ss) != 4: return (a, b, c, d) = ss # a + b + c > d if not (a + b + c > d): return # a^2 + b^2 + c^2 > d^2 / 3 (a2, b2, c2, d2) = map(sq, (a, b, c, d)) if 3 * (a2 + b2 + c2) <= d2: return # a^4 + b^4 + c^4 >= d^4 / 27 (a4, b4, c4, d4) = map(sq, (a2, b2, c2, d2)) if 27 * (a4 + b4 + c4) < d4: return # looks OK return 1 # difference check: no pair of lengths differs by a prime diff = lambda ss: not any(primes.is_prime(y - x) for (x, y) in subsets(ss, size=2)) # collect possible sides and perimeters for (ss, p) in solve(): if not is_quad(ss): continue # apply difference check d = diff(ss) printf("{ss} -> {p}; diff = {d}")Solution: The sides of the quadrilateral are (in metres): 4, 53, 61, 89.
And the perimeter is 207 m:
Without the additional condition that no two of the lengths differ by a prime number there is a second candidate solution:
But this fails the difference test (as: 83 − 4 = 79, and 61 − 59 = 2, both of which are primes).
If we assume the garden is a convex quadrilateral, then the length 4 side is considerably shorter than the other 3 sides, so the shape of the garden is roughly a (59, 61, 83) triangle.
We can take this triangle and “open out” two of the sides until we have introduced a gap of 4 between them. To give us shapes like this:
LikeLike
GeoffR 4:36 pm on 14 February 2023 Permalink |
LikeLike