Project Euler 9: (Iron)Python
- by Ben Griswold
In my attempt to learn (Iron)Python out in the open, here’s my solution for Project Euler Problem 9.
As always, any feedback is welcome.
# Euler 9
# http://projecteuler.net/index.php?section=problems&id=9
# A Pythagorean triplet is a set of three natural numbers,
# a b c, for which, # a2 + b2 = c2
# For example, 32 + 42 = 9 + 16 = 25 = 52.
# There exists exactly one Pythagorean triplet for which
# a + b + c = 1000. Find the product abc.
import time
start = time.time()
product = 0
def pythagorean_triplet():
for a in range(1,501):
for b in xrange(a+1,501):
c = 1000 - a - b
if (a*a + b*b == c*c):
return a*b*c
print pythagorean_triplet()
print "Elapsed Time:", (time.time() - start) * 1000, "millisecs"
a=raw_input('Press return to continue')