how can I calculate how many Pythagorean triangles share the same hypotenuse?
I don't need the parameters of the triangles, just how many are there, with the fastest time possible.
from math import sqrt
def hypotenuse(n):
count = 0
hypotenuse = n
for x in range(1, int(n / (sqrt(2))) + 1):
y = (((hypotenuse * hypotenuse) - (x * x)) ** 0.5)
if y % 1 == 0:
count += 1
return count
this is the code I have written but it turns out to be too slow.
UPDATE
I have changed the duplication method to sets instead of lists (even removed it completely) and changed the range from (1, n) to (1, int(n / sqrt(2))) still not fast enough