Skip to content

Instantly share code, notes, and snippets.

@dinks
Last active December 25, 2015 10:19
Show Gist options
  • Save dinks/6961041 to your computer and use it in GitHub Desktop.
Save dinks/6961041 to your computer and use it in GitHub Desktop.
Fibanocci with the Golden Ratio
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