If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
{20,48,52}, {24,45,51}, {30,40,50}
For which value of p ≤ 1000, is the number of solutions maximised?
In [1]:
20**2 + 48**2, 52**2, 20+48+52
Out[1]:
a + b + c = p -> a^2 + b^2 + c^2 + 2ab + 2ac + 2bc = p^2
a^2 + b^2 = c^2
2*(c^2 + ab + ac + bc) = p^2 -> 2 | p
In [2]:
for i in range(60,500):
solns = set()
p = i*2
for a in range(1,p):
for b in range(1,p-a):
c = p - a - b
s = set([a,b,c])
t = c*c - a*a - b*b
if s not in solns and t == 0:
solns.add(tuple(sorted(s)))
elif t < 0:
break
if len(solns) > 0:
print p, len(solns)
In [ ]: