Project Euler Problem 1: Multiples of 3 and 5

The source code for this problem can be found here.

Problem Statement

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\).

Solution Discussion

Nothing sophisticated here, explicitly perform the computation.

Solution Implementation

def solve():
    """ Compute the answer to Project Euler's problem #1 """
    num_range = range(1, 1000)
    valid = lambda n: n % 3 == 0 or n % 5 == 0  # number must be a multiple of 3 OR 5
    numbers = [i for i in num_range if valid(i)]
    answer = sum(numbers)
    return answer


expected_answer = 233168
solutions.problem1.solve()

Compute the answer to Project Euler’s problem #1