Ivankooo1

Combinations

Jun 22nd, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function numb(input){
  2.   let n = Number(input.shift());
  3.   let counter = 0;
  4.  
  5.   for(let x1 = 0;x1 <= n;x1++){
  6.      for(let x2 = 0;x2 <= n;x2++){
  7.         for(let x3 = 0;x3 <= n;x3++){
  8.            for(let x4 = 0;x4 <= n;x4++){
  9.               for(let x5 = 0;x5 <= n;x5++){
  10.                let sum = x1 + x2 + x3 + x4 + x5;
  11.                if(sum === n){
  12.                   counter++;
  13.                  }
  14.                  
  15.               }
  16.            }
  17.         }
  18.      }
  19.   }
  20.  
  21.        
  22.   console.log(counter);
  23. }
  24.  
  25. numb([5]);
Advertisement
Add Comment
Please, Sign In to add comment