Today, a short post with a Python recursive function that finds the nth Fibonacci number.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
File: pyscimark_fibonacci.py ---------------------------- cache = {1:1, 2:1} def fib(n, cache): if n not in cache: cache[n] = fib(n-1, cache) + fib(n-2, cache) return cache[n] assert([fib(i, cache) for i in range(1,10)] == [1,1,2,3,5,8,13,21,34]) |
Want more fast scripts? Check out these scripts to find a list of prime numbers and the divisors of a number.
Please, add +Marina Mele in your comments. This way I will get a notification email and I will answer you as soon as possible! :-)