Skip to content

Instantly share code, notes, and snippets.

@kipanshi
Created October 19, 2017 14:12
Show Gist options
  • Save kipanshi/8126958be6a46cac8ed3c5e6b76be978 to your computer and use it in GitHub Desktop.
Save kipanshi/8126958be6a46cac8ed3c5e6b76be978 to your computer and use it in GitHub Desktop.
Fibbonaci Fast dobule Algo
var yourself = {
fibonacci: function(n) {
return this._fib(n)[0]
},
_fib : function(n) {
if (n === 0) {
return [0, 1]
} else {
let half = this._fib(Math.floor(n / 2));
let a = half[0]
let b = half[1]
let c = a * (b * 2 - a)
let d = a * a + b * b
if (n % 2 === 0) {
return [c, d]
} else {
return [d, c + d]
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment