title: How to List all Combinations of N Indices that Equal X
body: <p>I am trying to return an array with the following rules:<br>
  1. All unique combinations that sum to X<br>
  2. Each number is assigned a letter<br>
  3. Each letter can only be used once in a sum   </p>
  
  <pre><code>// Cartesian join
  function cartesian() {
    let r = []
    let arg = arguments
    let max = arg.length-1
  
    function helper(arr, i) {
      for (let j=0, l=arg[i].length; j&lt;l; j++) {
        let a = arr.slice(0); // clone arr
        a.push(arg[i][j]);
        if (i==max)
          r.push(a);
        else
          helper(a, i+1);
      }
    }
    helper([], 0);
    return r;
  }
  
  let a = ['A','B','C'];
  let a1 = ['1','2','3'];
  
  let arrays = cartesian(a, a1)
  
  for(let i=1; i&lt;arrays.length; i++) {
    file[i] = arrays[i].join('').toString();
  }
  </code></pre>
  
  <p>The cartesian join will output [A1, B1, C1, A2, B2...]</p>
  
  <p>How do I then add up combinations of N indices that have a sum of X, while only using a number once from each letter index?</p>
  
  <p>Where N is number of letters that apply to sum.
  Where X is sum total.</p>
  
  <p>For instance if N = 3 and X = 5,</p>
  
  <p>Output would be {A1, B1, C3}, {A1, B2, C2}, {A1, B3, C1}, {B2, C3}, {B3, C2}, etc...</p>