diff --git a/app/main.py b/app/main.py index 68287892f..970d9e1ac 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,29 @@ -from typing import Callable +from typing import Callable, Any +from functools import wraps def cache(func: Callable) -> Callable: - # Write your code here - pass + results_dict = {} + + @wraps(func) + def wrapper(*args) -> Any: + key = args + if key not in results_dict: + results_dict[key] = func(*args) + print("Calculating new result") + else: + print("Getting from cache") + return results_dict[key] + + return wrapper + + +@cache +def long_time_func(num1: int, num2: int, num3: int) -> int: + result = (num1 ** num2 ** num3) % (num1 * num3) + return result + + +@cache +def long_time_func_2(n_tuple: tuple, power: int) -> int: + return [number ** power for number in n_tuple]