Skip to content

Instantly share code, notes, and snippets.

@igorvanloo
Last active July 23, 2021 06:46
Show Gist options
  • Save igorvanloo/c2185a52d59d19ba4d13df2d3ed04717 to your computer and use it in GitHub Desktop.
Save igorvanloo/c2185a52d59d19ba4d13df2d3ed04717 to your computer and use it in GitHub Desktop.
Pythagorean Triple Function
def ppt(limit):
triples = []
for m in range(2,int(math.sqrt(limit))+1):
for n in range(1,m):
if (m+n) % 2 == 1 and math.gcd(m,n) == 1:
a = m**2 + n**2
b = m**2 - n**2
c = 2*m*n
p = max(a,b,c)
for k in range(1,int(limit/p)+1):
triples.append([k*b,k*c,k*a])
return triples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment