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 rightangled triangle that can have wholenumber 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 threefigure palindromic hypotenuse. However, just one of the triangles was very nearly a 45° rightangled triangle (having a relative difference between the adjacent side lengths of less than 2%).
In ascending order, what were my siblings’ ages?

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 3digit 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# 3figure 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 rightangled 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()