Skip to content

Instantly share code, notes, and snippets.

@edalorzo
Created November 25, 2012 03:19
Show Gist options
  • Select an option

  • Save edalorzo/4142271 to your computer and use it in GitHub Desktop.

Select an option

Save edalorzo/4142271 to your computer and use it in GitHub Desktop.
Project Euler-Problem #9
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