Advertisement
Liliana797979

viarno reshenie combinations2

Feb 13th, 2021
94
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.     let validCombinationsCount = 0;
  4.     for (let x1 = 0; x1 <= n; x1++) {
  5.         for (let x2 = 0; x2 <= n; x2++) {
  6.             for (let x3 = 0; x3 <= n; x3++) {
  7.                 if (x1 + x2 + x3 === n) {
  8.                     validCombinationsCount++;
  9.                 }
  10.             }
  11.         }
  12.     }
  13.     console.log(validCombinationsCount);
  14. }
  15.  
  16.  
  17. combinations();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement