Advertisement
Spocoman

Combinations

Jan 4th, 2022 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function combinations(input) {
  2.     let n = parseInt(input[0]),
  3.         combinations = 0;
  4.  
  5.     for (let a = 0; a <= n; a++) {
  6.         for (let b = 0; b <= n; b++) {
  7.             for (let c = 0; c <= n; c++) {
  8.                 if (a + b + c === n){
  9.                     combinations++;
  10.                 }
  11.             }
  12.         }
  13.     }
  14.  
  15.     console.log(combinations);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement