Skip to content

Instantly share code, notes, and snippets.

@XanderStrike
Last active August 29, 2015 14:23
Show Gist options
  • Save XanderStrike/41d5f51bef9f9353faa4 to your computer and use it in GitHub Desktop.
Save XanderStrike/41d5f51bef9f9353faa4 to your computer and use it in GitHub Desktop.
function fast_double_fib(n) {
var a, b, c, d
if (n == 0) {
return [0, 1]
} else {
l = fast_double_fib(Math.floor(n / 2))
a = l[0]
b = l[1]
c = a * (b * 2 - a)
d = a * a + b * b
d = a * a + b * b
if (n % 2 == 0) {
return [c, d]
} else {
return [d, c + d]
}
}
}
console.log(fast_double_fib(1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment