Solution for problems 1,2
This commit is contained in:
30
src/Python/Problem001.py
Normal file
30
src/Python/Problem001.py
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/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()}")
|
||||
Reference in New Issue
Block a user