Skip to main content
1 of 2
Solomon Ucko
  • 1.6k
  • 1
  • 10
  • 17

Another formula I found out about: $$f(n)=[\frac{\phi^n}{\sqrt5}]$$ (square brackets mean rounding down AKA truncation AKA conversion to int).

from math import sqrt

root_five = sqrt(5)
phi = (root_five + 1) / 2

def fibonacci(n):
    return int((phi ** n) / root_five)

Note: only supports the normal fibonacci sequence, may or may not work for negatives.

Solomon Ucko
  • 1.6k
  • 1
  • 10
  • 17