From fd44ce1fd994fb80aac693bb3a416215d3ecb42d Mon Sep 17 00:00:00 2001 From: Serhii Date: Fri, 18 Oct 2024 18:45:55 +0300 Subject: [PATCH] solution --- app/main.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892..b7a7d3dd 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,27 @@ -from typing import Callable +from typing import Callable, Any def cache(func: Callable) -> Callable: - # Write your code here - pass + func_cache = {} + + def wrapper(*args) -> Any: + if args in func_cache: + print("Getting from cache") + return func_cache[args] + else: + print("Calculating new result") + result = func(*args) + func_cache[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(n_tuple: tuple, power: int) -> Any: + return [number ** power for number in n_tuple]