diff options
Diffstat (limited to 'users/wpcarro/scratch/facebook/interview-cake/nth-fibonacci.py')
-rw-r--r-- | users/wpcarro/scratch/facebook/interview-cake/nth-fibonacci.py | 6 |
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] |