Created
February 10, 2015 20:54
-
-
Save tennisonchan/0e3b4f46ccc8be8efb2c to your computer and use it in GitHub Desktop.
breaking down number into combination of fibonacci number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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