Skip to main content
1 of 7
TheCoffeeCup
  • 9.5k
  • 4
  • 38
  • 96

If you are just looking for a simple function that gets the nth Fibonacci number, you can use phi:

$$\frac{\sqrt5 + 1}2$$

To calculate the nth fibonacci number:

$$fib(n)=round(\phi^n/\sqrt5)$$

I don't know python very well, but if you can store the value of phi and square root of 5, you can do:

var yourself = { fibonacci : function(n) { if (n === 0) { return 0; } if (n === 1) { return 1; } return round(pow(phi, n) / sqrt5); } }; 
TheCoffeeCup
  • 9.5k
  • 4
  • 38
  • 96