project-euler/src/Python/Problem001.py
2021-06-05 15:03:42 +02:00

31 lines
623 B
Python

#!/usr/bin/python3
"""
Created on 14 Mar 2017
@author: David Doblas Jiménez
@email: daviddoji@pm.me
Solution for problem 1 of Project Euler
https://projecteuler.net/problem=1
"""
from utils import timeit
@timeit("Problem 1")
def compute():
"""
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.
"""
ans = sum(x for x in range(1000) if (x % 3 == 0 or x % 5 == 0))
return ans
if __name__ == "__main__":
print(f"Result for problem 1: {compute()}")