Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * @author: ZEGHBA Yahia
  3.  *
  4.  */
  5.  
  6. let sum = 4; // stairs number
  7. let cases = [1,2]; // step cases
  8. let p = []; // probabilities
  9.  
  10. function a(sum,solution,depth,p) {
  11.     if(sum == 0){
  12.         console.log(solution); // solution
  13.         // clone array
  14.         p.push(solution.slice(0));
  15.         return p;
  16.     }
  17.  
  18.     if(sum > 0){
  19.         for (let i = 0; i < cases.length; i++) {
  20.             if((sum-cases[i])>=0){
  21.                 console.log("case: "+i);
  22.                 console.log("depth: "+depth); // depth tree
  23.                 // remove elements (from :depth to:length of array) from: array(solution)
  24.                 solution.splice(depth);
  25.                 solution.push(cases[i]);
  26.                 a(sum-cases[i],solution,depth+1,p);
  27.             }else{
  28.                 console.log("coucou");
  29.             }
  30.         }    
  31.     }
  32.  
  33.     return p;
  34. }
  35.  
  36.  
  37. console.log(a(sum,[],0,p));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement