Skip to content

Instantly share code, notes, and snippets.

@raheemazeezabiodun
Created July 22, 2019 12:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raheemazeezabiodun/dcde041c3f23f92dc55004562d54e0f1 to your computer and use it in GitHub Desktop.
Save raheemazeezabiodun/dcde041c3f23f92dc55004562d54e0f1 to your computer and use it in GitHub Desktop.
A fibonacci sequence with a better approach
def slow_fibonacci_number(n):
if n <= 1:
return n
return slow_fibonacci_number(n - 1) + slow_fibonacci_number(n - 2)
def fast_fibonacci_number(n):
numbers = [0, 1]
for num in range(2, n+1):
numbers.append(numbers[num - 1] + numbers[num - 2])
return numbers[n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment