TZinovieva

Combinations JS

Oct 22nd, 2022
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function combinations(input) {
  2.     let n = Number(input[0]);
  3.  
  4.     let counter = 0;
  5.  
  6.     for (let x1 = 0; x1 <= n; x1++) {
  7.             for (let x2 = 0; x2 <= n; x2++) {
  8.                 for (let x3 = 0; x3 <= n; x3++) {
  9.                     if (x1 + x2 + x3 === n) {
  10.                     counter++;
  11.                 }
  12.             }  
  13.         }
  14.     }
  15.     console.log(`${counter}`);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment