Created
November 25, 2012 03:19
-
-
Save edalorzo/4142271 to your computer and use it in GitHub Desktop.
Project Euler-Problem #9
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 calc_triple(m, n): | |
| a = n ** 2 - m ** 2 | |
| b = 2 * m * n | |
| c = n ** 2 + m ** 2 | |
| return (a,b,c) | |
| def find_triplet(): | |
| j = 1 | |
| sum = 0 | |
| while True: | |
| k = j + 1 | |
| while True: | |
| (a,b,c) = calc_triple(j,k) | |
| sum = a + b + c | |
| if sum >= 1000: | |
| break | |
| k += 1 | |
| if sum == 1000: | |
| return (a,b,c) | |
| j += 1 | |
| if __name__ == '__main__': | |
| a,b,c = find_triplet() | |
| print "The product of the Pythagorean triplet (%d,%d,%d) is %d" % (a,b,c,a*b*c) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment