Project Euler 5: (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:45:09 +0000
Indexed on
2010/12/06
16:59 UTC
Read the original article
Hit count: 543
In my attempt to learn (Iron)Python out in the open, here’s my solution for Project Euler Problem 5.
As always, any feedback is welcome.
# Euler 5
# http://projecteuler.net/index.php?section=problems&id=5
# 2520 is the smallest number that can be divided by each
# of the numbers from 1 to 10 without any remainder.
# What is the smallest positive number that is evenly
# divisible by all of the numbers from 1 to 20?
import time
start = time.time()
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
print reduce(lcm, range(1, 20))
print "Elapsed Time:", (time.time() - start) * 1000, "millisecs"
a=raw_input('Press return to continue')
© Johnny Coder or respective owner