Files
euler-project/problems/001_problem.py
2020-04-14 15:07:07 -04:00

57 lines
994 B
Python

# 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.
import functools
import time
def timer(f):
""" Decorator function to calculate compute time of passed function. """
@functools.wraps(f)
def wrapper_timer(*args,**kwargs):
start_time = time.perf_counter()
f(*args, **kwargs)
end_time = time.perf_counter()
run_time = end_time - start_time
print("Finished {func.__name__!r} in {run_time:.4f} seconds...")
return f
return wrapper_timer
def check_divisibility(num, dict_multiples: dict) -> bool:
dummy = 1
for m in dict_multiples:
dummy *= num%m
if dummy == 0:
return True
else:
return False
@timer
def main():
multiples = {3,5}
sumval = 0
for n in range(1000):
r = check_divisibility(n,multiples)
if r:
sumval += n
print(sumval)
main()