Demo entry 6655527

fibbonacci

   

Submitted by anonymous on Oct 27, 2017 at 03:20
Language: Python. Code size: 271 Bytes.

def fib(n):
  if n in cache:
    return cache[n] # checks if fib(n) is already in cache
  if n == 0 or n == 1:
    val = 1 # base cases
  else:
    val = fib(n-1) + fib(n-2) # calls fib function recursively
  cache[n] = val # stores fib(n) to cache
  return val

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).