Friday, August 29, 2008

Problem 9 Pythagorean triplet summing to 1000

/home/user> python pythagorus.py
['Sat Aug 30 02:46:51 2008', 200, 375, 425, 'Sat Aug 30 02:47:02 2008']
/home/user> cat pythagorus.py
import time
starttime = time.asctime()
def findPythag():
for c in range(334,1001):
for b in range(0, c):
for a in range(0,b):
if (a*a+b*b==c*c) and (a + b + c == 1000):
return [starttime,a,b,c,time.asctime()]
return "Not Found"

print findPythag()

No comments: