Skip to content

Instantly share code, notes, and snippets.

@giannispan
Created February 1, 2016 17:13
Show Gist options
  • Save giannispan/bdaab6e5470f48d77322 to your computer and use it in GitHub Desktop.
Save giannispan/bdaab6e5470f48d77322 to your computer and use it in GitHub Desktop.
Tribonacci Sequence
function tribonacci(signature,n){
console.log(signature);
console.log(n);
var i;
var fib = new Array();
if (n == 0) return fib;
if (n > 3) {
fib[0] = signature[0];
fib[1] = signature[1];
fib[2] = signature[2];
for (i = 3; i < n; i++)
fib[i] = fib[i-3] + fib[i-2] + fib[i-1];
return fib;
}
else if (n <= 3) {
for (i = 0; i < n; i++)
fib[i] = signature[i];
return fib;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment