about summary refs log tree commit diff
path: root/users/wpcarro/scratch/facebook/interview-cake/nth-fibonacci.py
diff options
context:
space:
mode:
Diffstat (limited to 'users/wpcarro/scratch/facebook/interview-cake/nth-fibonacci.py')
-rw-r--r--users/wpcarro/scratch/facebook/interview-cake/nth-fibonacci.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/users/wpcarro/scratch/facebook/interview-cake/nth-fibonacci.py b/users/wpcarro/scratch/facebook/interview-cake/nth-fibonacci.py
new file mode 100644
index 000000000000..4629798cf711
--- /dev/null
+++ b/users/wpcarro/scratch/facebook/interview-cake/nth-fibonacci.py
@@ -0,0 +1,6 @@
+def fib(n):
+    cache = (0, 1)
+    for _ in range(n):
+        a, b = cache
+        cache = (b, a + b)
+    return cache[0]