1. Ian Lewis
  2. projecteuler

Commits

Ian Lewis  committed 14eebad

Added solution to problem 5 (Python)

  • Participants
  • Parent commits 2a9ed1d
  • Branches default

Comments (0)

Files changed (1)

File python/euler5.py

View file
+"""
+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?
+"""
+
+X = 20
+
+def count(start=0, step=1):
+    while True:
+        yield start
+        start += step
+
+def euler5(x):
+    # TODO: Optimize this. Runs in reasonable time up to x==18
+    # but is pretty slow after that
+    divisors = range(1,x+1)
+    for num in count(x, step=x):
+        if all([num % y == 0 for y in divisors]):
+            return num
+
+if __name__ == '__main__':
+    print euler5(X)