Skip to content

Instantly share code, notes, and snippets.

@tennisonchan
Created February 10, 2015 20:54
Show Gist options
  • Save tennisonchan/0e3b4f46ccc8be8efb2c to your computer and use it in GitHub Desktop.
Save tennisonchan/0e3b4f46ccc8be8efb2c to your computer and use it in GitHub Desktop.
breaking down number into combination of fibonacci number
fib = [1,2,3,5,8,13,21,34,55,89,144];
function dec2fib(num) {
list = [];
for(var i=fib.length;i<0;i--){
if(fib[i] < num){
num -= fib[i];
list.push(i);
}
}
return list;
}
function randomNumber() {
return Math.floor(Math.random() * 100);
}
function main() {
var num = randomNumber();
var list = dec2fib(num);
console.log(list);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment