diff --git a/app/main.py b/app/main.py index 68287892..dfbaac7b 100644 --- a/app/main.py +++ b/app/main.py @@ -2,5 +2,33 @@ def cache(func: Callable) -> Callable: - # Write your code here - pass + cache_data = {} + + def wrapper(*args) -> Callable: + if args in cache_data: + print("Getting from cache") + return cache_data[args] + print("Calculating new result") + result = func(*args) + cache_data[args] = result + return result + + return wrapper + + +@cache +def long_time_func(a: int, b: int, c: int) -> int: + return (a ** b ** c) % (a * c) + + +@cache +def long_time_func_2(numbers_tuple: tuple, power: int) -> list: + return [number ** power for number in numbers_tuple] + + +long_time_func(1, 2, 3) +long_time_func(2, 2, 3) +long_time_func_2((5, 6, 7), 5) +long_time_func(1, 2, 3) +long_time_func_2((5, 6, 7), 10) +long_time_func_2((5, 6, 7), 10)