Project Euler problem 1 says:
Find the sum of all the multiples of 3 or 5 below 1000.
I have written a program that will return the sum of the multiples of any list of positive integers. So for example if I wanted to know the sum of every integer that was a multiple of 3 and 5 that is less than 10 I would add 3,5,6, and 9 to get 23.
My function can do this for any number of positive integers, between any range that starts from 1.
# Function to return sum of multiples that are within a certain range
def MultiplesSum(multiple, end, start=1):
mSum = 0
naturals = range(start, end)
offset = -start
if start == 0:
raise ZeroDivisionError('Cannot start with the number 0')
for num in multiple:
for i in naturals:
if i % num == 0 and naturals[i+offset] != 0:
# print mSum,"+", i,"=",i+mSum
mSum += i
naturals[i+offset] = 0
i += 1
return mSum
problem1 = MultiplesSum([3,5,2], 16)
print problem1
# prints 88