Project Euler 5: (Iron)Python
- by Ben Griswold
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')