aboutsummaryrefslogtreecommitdiff
path: root/entries/Tarcisio-Teixeira/fib.py
diff options
context:
space:
mode:
authorTarcisio-Teixeira2022-10-23 23:48:02 +0000
committerGitHub2022-10-23 23:48:02 +0000
commit97d0bca7470bef068b5852a94c5e51c103b0400c (patch)
tree4688faf432ea9a31d5717e2f11002a07ba6d9fba /entries/Tarcisio-Teixeira/fib.py
parent668e1a0266a0c59a0e420571dbbcb445e72361ae (diff)
Create fib.py
Diffstat (limited to 'entries/Tarcisio-Teixeira/fib.py')
-rw-r--r--entries/Tarcisio-Teixeira/fib.py5
1 files changed, 5 insertions, 0 deletions
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))