Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiik05 committed Oct 18, 2024
1 parent 5891c38 commit fd44ce1
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit fd44ce1

Please sign in to comment.