Commits

Ian Lewis committed 83d75c0

Added solution for problem 1 (Python)

  • Participants

Comments (0)

Files changed (1)

+u"""
+If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
+
+Find the sum of all the multiples of 3 or 5 below 1000.
+"""
+
+def euler1():
+    multiples = set()
+
+    # Instead of looping from 1 to 1000 and checking a mod
+    # calculate the multiples directly
+    for val in (3,5):
+        m = 1
+        while val:
+            multiple = val * m
+            if multiple < 1000:
+                multiples.add(multiple)
+            else: 
+                break
+            m += 1
+    return sum(multiples)
+
+if __name__ == '__main__':
+    print euler1()