Last active
August 29, 2015 13:57
-
-
Save mstade/9483764 to your computer and use it in GitHub Desktop.
Fibonacci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 0 and below will yield 0, everything else follows the sequence. | |
function fib(n) { | |
const sq = Math.sqrt(5) | |
, gr = (1 + sq) / 2 | |
return Math.floor(Math.pow(gr, n) / sq + 0.5) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment