Project Euler 6: (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:46:00 +0000 Indexed on 2010/12/06 16:59 UTC
Read the original article Hit count: 317

In my attempt to learn (Iron)Python out in the open, here’s my solution for Project Euler Problem 6

As always, any feedback is welcome.

# Euler 6
# http://projecteuler.net/index.php?section=problems&id=6
# Find the difference between the sum of the squares of
# the first one hundred natural numbers and the square
# of the sum.
import time
start = time.time()

square_of_sums = sum(range(1,101)) ** 2
sum_of_squares = reduce(lambda agg, i: agg+i**2, range(1,101))
print square_of_sums - sum_of_squares

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