Last active
December 25, 2015 10:19
-
-
Save dinks/6961041 to your computer and use it in GitHub Desktop.
Fibanocci with the Golden Ratio
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
var phi = (1 + Math.sqrt(5)) / 2; | |
var fib_gr = function (n) { | |
return Math.floor((Math.pow(phi, n) / Math.sqrt(5)) + (1 / 2)); | |
}; | |
for (var i = 1; i < 20; ++i) { | |
console.log(i, '->', fib_gr(i)); | |
} | |
var fib_recursion = function (n) { | |
if (n === 0 || n === 1) { | |
return n; | |
} | |
return fib_recursion(n-1) + fib_recursion(n-2); | |
}; | |
for (var i = 1; i < 20; ++i) { | |
console.log(i, '->', fib_recursion(i)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment