Ctrl-m h shows keyboard shortcuts


In [6]:
"""
Problem 1
=========


   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.
"""

from itertools import *

def project_euler_1(x, y, a, b):
    """Returns sum of multiples of a and b between x and y."""
    return sum(set(chain(range(x, y, a), range(x, y, b))))

# project_euler_1(0, 1000, 3, 5)
    
# timeit project_euler_1(0,1000,3,5)

# %prun project_euler_1(0,1000,3,5)


The slowest run took 4.89 times longer than the fastest. This could mean that an intermediate result is being cached 
10000 loops, best of 3: 24.9 µs per loop