Problem 39 : Integer right triangles
Problem Statement
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?
Solution
def triplets(p):
val=[]
for a in range(1,p):
b=int((p*(p-2*a))/(2*(p-a)))
c=p-a-b
if (a*a+b*b)==c*c and a+b>c and b>a:
val.append([a,b,c])
return val
val2=[]
temp=[]
for p in range(3,1001):
temp=triplets(p)
if len(temp)>len(val2):
val2=temp
peri = p
print(peri)
Output
840