Created
July 13, 2013 08:16
-
-
Save Ayrx/5989957 to your computer and use it in GitHub Desktop.
A generator for Pythagorean triplets.
This file contains 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 pythagorean_triplets(n): | |
for i in xrange(1, n): | |
j = i+1 | |
k = j+1 | |
while k <= n: | |
while k*k < (i*i) + (j*j): | |
k += 1 | |
if k*k == (i*i) + (j*j) and k <= n: | |
yield i, j, k | |
j += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment