ProdanTenev

Combinations

Mar 2nd, 2022
853
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 0.40 KB | None | 0 0
  1. function combinations(input) {
  2.     let num = Number(input[0]);
  3.     let combinationsCounter = 0;
  4.     for (let x = 0; x <= num; x++) {
  5.         for (let y = 0; y <= num; y++) {
  6.             for (let z = 0; z <= num; z++) {
  7.                 if (x + y + z == num) {
  8.                     combinationsCounter++;
  9.                 }
  10.             }            
  11.         }
  12.     }
  13.     console.log(combinationsCounter);
  14. }
Advertisement
Add Comment
Please, Sign In to add comment