From 97d0bca7470bef068b5852a94c5e51c103b0400c Mon Sep 17 00:00:00 2001 From: Tarcisio-Teixeira Date: Sun, 23 Oct 2022 16:48:02 -0700 Subject: Create fib.py --- entries/Tarcisio-Teixeira/fib.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 entries/Tarcisio-Teixeira/fib.py (limited to 'entries/Tarcisio-Teixeira/fib.py') diff --git a/entries/Tarcisio-Teixeira/fib.py b/entries/Tarcisio-Teixeira/fib.py new file mode 100644 index 0000000..1246517 --- /dev/null +++ b/entries/Tarcisio-Teixeira/fib.py @@ -0,0 +1,5 @@ +def fib(n,arr={},v =-1): + if v>=0: + arr[n]=v + return v + return arr[n] if n in arr.keys() else fib(n, arr, (3*n*n*n - 9*n*n+13*n)//6 if n <= 3 else fib(n//2-1,arr)*fib(n-n//2,arr) + fib(n//2,arr)*fib(n-n//2+1,arr)) -- cgit v1.2.3-70-g09d2 From d0513187789505955e41441973c63848ec247cbc Mon Sep 17 00:00:00 2001 From: Tarcisio-Teixeira Date: Sun, 23 Oct 2022 17:02:58 -0700 Subject: Update fib.py --- entries/Tarcisio-Teixeira/fib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'entries/Tarcisio-Teixeira/fib.py') diff --git a/entries/Tarcisio-Teixeira/fib.py b/entries/Tarcisio-Teixeira/fib.py index 1246517..a73cdd2 100644 --- a/entries/Tarcisio-Teixeira/fib.py +++ b/entries/Tarcisio-Teixeira/fib.py @@ -2,4 +2,4 @@ def fib(n,arr={},v =-1): if v>=0: arr[n]=v return v - return arr[n] if n in arr.keys() else fib(n, arr, (3*n*n*n - 9*n*n+13*n)//6 if n <= 3 else fib(n//2-1,arr)*fib(n-n//2,arr) + fib(n//2,arr)*fib(n-n//2+1,arr)) + return arr[n] if n in arr.keys() else fib(n, arr, (2*n*n*n - 9*n*n+13*n)//6 if n <= 3 else fib(n//2-1,arr)*fib(n-n//2,arr) + fib(n//2,arr)*fib(n-n//2+1,arr)) -- cgit v1.2.3-70-g09d2