Automatic commit performed through alias...
This commit is contained in:
@@ -8,20 +8,7 @@
|
|||||||
#
|
#
|
||||||
# Find the sum of all the multiples of 3 or 5 below 1000.
|
# Find the sum of all the multiples of 3 or 5 below 1000.
|
||||||
|
|
||||||
|
import decorators
|
||||||
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:
|
def check_divisibility(num, dict_multiples: dict) -> bool:
|
||||||
|
|
||||||
@@ -34,7 +21,7 @@ def check_divisibility(num, dict_multiples: dict) -> bool:
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@f_timer
|
@decorators.function_timer
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
multiples = {3,5}
|
multiples = {3,5}
|
||||||
|
|||||||
0
problems/__init__.py
Normal file
0
problems/__init__.py
Normal file
20
problems/decorators.py
Normal file
20
problems/decorators.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
Collection of decorators that could be helpful while solving problems.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Function decorator which calculates the time required to execute a function.
|
||||||
|
def function_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
|
||||||
Reference in New Issue
Block a user