diff options
-rw-r--r-- | scratch/facebook/interview-cake/nth-fibonacci.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/scratch/facebook/interview-cake/nth-fibonacci.py b/scratch/facebook/interview-cake/nth-fibonacci.py new file mode 100644 index 000000000000..4629798cf711 --- /dev/null +++ b/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] |