From 281047e73c8de79191fac1cc46741d9f9e7ff4f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D1=83=D0=B7=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=9F=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=BE?= <124675990+CrazyDuck192@users.noreply.github.com> Date: Tue, 21 Mar 2023 20:35:25 +0200 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BC=D0=B0=D1=88=D0=BD=D1=8F=20?= =?UTF-8?q?=D1=80=D0=BE=D0=B1=D0=BE=D1=82=D0=B0=20=E2=84=9613=20(=E2=84=96?= =?UTF-8?q?17.9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 17.9.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 17.9.py diff --git a/17.9.py b/17.9.py new file mode 100644 index 0000000..c442b14 --- /dev/null +++ b/17.9.py @@ -0,0 +1,31 @@ +def decorator(maximum): + cache = [None for _ in range(maximum)] + + def _decorator(func): + + def __decorator(arg: int, **kw): + if arg > maximum: + return f'Out of range ({arg})' + + if cache[arg-1] != None: + return f'Already in cache: {cache[arg-1]}' + else: + y = func(arg, **kw) + cache[arg-1] = y + return y + + return __decorator + + return _decorator + + +@ decorator(10) +def fib(n, f0=1, f1=1, count=1): + if count < n: + return fib(n, f0=f1, f1=f0+f1, count=count+1) + return f1 + +if __name__ == '__main__': + print(fib(5)) + print(fib(5)) + print(fib(11)) \ No newline at end of file