Project Euler 9: (Iron)Python

Posted by Ben Griswold on Johnny Coder See other posts from Johnny Coder or by Ben Griswold
Published on Mon, 13 Sep 2010 02:48:51 +0000 Indexed on 2010/12/06 16:59 UTC
Read the original article Hit count: 344

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')

© Johnny Coder or respective owner

Related posts about ironpython

Related posts about languages