Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author: ZEGHBA Yahia
- *
- */
- let sum = 4; // stairs number
- let cases = [1,2]; // step cases
- let p = []; // probabilities
- function a(sum,solution,depth,p) {
- if(sum == 0){
- console.log(solution); // solution
- // clone array
- p.push(solution.slice(0));
- return p;
- }
- if(sum > 0){
- for (let i = 0; i < cases.length; i++) {
- if((sum-cases[i])>=0){
- console.log("case: "+i);
- console.log("depth: "+depth); // depth tree
- // remove elements (from :depth to:length of array) from: array(solution)
- solution.splice(depth);
- solution.push(cases[i]);
- a(sum-cases[i],solution,depth+1,p);
- }else{
- console.log("coucou");
- }
- }
- }
- return p;
- }
- console.log(a(sum,[],0,p));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement