Files
euler-project/problems/001_problem.py
2020-04-14 20:47:43 -04:00

50 lines
836 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.
def f_timer(passed_f):
def inner_f(*args, **kwargs):
import time
t1 = time.time()
value = passed_f(*args, **kwargs)
t2 = time.time()
t3 = t2 - t1
print("The function {} ran for {:4f} seconds... ".format(passed_f.__name__,t3))
return value
return inner_f
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
@f_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()