Last active
July 23, 2021 06:46
-
-
Save igorvanloo/c2185a52d59d19ba4d13df2d3ed04717 to your computer and use it in GitHub Desktop.
Pythagorean Triple Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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