Sunday Times Teaser 3017 – Mr Green’s Scalene Mean Machine
by Stephen Hogg
Published Sunday July 19 2020 (link)
My maths teacher, Mr. Green, stated that the average of the squares of any two different odd numbers gives the hypotenuse of a right-angled triangle that can have whole-number unequal sides, and he told us how to work out those sides.
I used my two sisters’ ages (different odd prime numbers) to work out such a triangle, then did the same with my two brothers’ ages (also different odd prime numbers). Curiously, both triangles had the same three-figure palindromic hypotenuse. However, just one of the triangles was very nearly a 45° right-angled triangle (having a relative difference between the adjacent side lengths of less than 2%).
In ascending order, what were my siblings’ ages?
-
Brian Gladman permalink1234567891011121314151617181920212223242526272829303132from itertools import combinationsfrom collections import defaultdict# odd primes whose squares are less than 1000pr = {3, 5, 7}pr = pr | {x for x in range(11, 32, 2) if all(x % p for p in pr)}# collect triangles with three digit palindromic hypotenusesh2t = defaultdict(list)for a, b in combinations(pr, 2):h = (a * a + b * b) // 2if 100 <= h < 1000 and h // 100 == h % 10:h2t[h].append((a, b))# consider hypotenuses with pairs of solutionsfor h, v in h2t.items():if len(v) >= 2:# look for triangles with this hypotenuse whose# other two sides are less than 2% differentcnt = 0for x in range(1, h):y2 = h * h - x * xy = round(y2 ** 0.5)if y * y == y2 and x <= y:if 100 * abs(x - y) < 2 * max(x, y):cnt += 1# there must be exactly one such triangleif cnt == 1:ages = tuple(sorted(v[0] + v[1]))print(f"Ages = {ages} (hypoteneuse = {h}).")
-
Erling Torkildsen permalink12345678910111213141516171819202122232425262728from itertools import combinations, permutations# PrimesP = set(x for x in range(3, 33, 2) if all(x % mfor m in range(3, x, 2)))# Pairs of primesP2 = combinations(P, 2)# Set of three digit palindromesPAL = set()for a in range(1,10):for b in range(10):PAL.add(100*a + 10*b + a)ans = set()# Write palindromic hypothenuses as a sum of two squaresfor m, n in permutations(list(n*n for n in range(1, 31)), 2):for z in PAL:if m + n == z:if 0.98 < 2*(m*n)**0.5/(n - m) < 1.02:for a, b in P2:if (a**2 + b**2)//2 == z:ans.add(a)ans.add(b)print("The ages were: ",sorted(ans))
-
GeoffR permalink123456789101112131415161718192021222324252627282930313233343536373839404142434445464748# list of prime number agesprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29,31, 37, 41, 43, 47, 53, 59, 61, 67,71, 73, 79, 83, 89, 97]# list of 3-digit palindromic numbersPAL = [(100*a + 10*b + a) for a in range(1,10)for b in range(1,10)]def is_green_tri(a, b, h):if a**2 + b**2 == 2 * h:return Truedef is_near45_tri(c, d, h):if c**2 + d**2 == h**2:if (d - c) * 100 < 2 * d:return True# find sisters' prime ages (s1, s2)for s1 in primes:for s2 in primes:if s2 <= s1:continue# 3-figure hypotenuse must be palindromicfor hyp in PAL:if is_green_tri(s1, s2, hyp):# find brothers' prime ages (b1, b2)for b1 in primes:if b1 in (s1, s2):continuefor b2 in primes:if b2 in (s1, s2) or b2 <= b1:continueif is_green_tri(b1, b2, hyp):# find near 45 degree right-angled triangle# with two adjacent sides < 2% differentfor c in range(100, 999):for d in range(c+1, 999):if is_near45_tri(c, d, hyp):print(f"Sisters ages: {s1},{s2}")print(f"Brothers ages: {b1},{b2}")print(f"Triangle sides: {c},{d},{hyp}")print()