title: Generating combinations from an array which == a specified amount?
body: <p>I need to get all the possible number combinations from <code>denom_arr</code> which equal the <code>amt</code>.</p>
  
  <pre><code>denom_arr = [4,3,1]
  amt = 10
  </code></pre>
  
  <p>This case would produce:</p>
  
  <ol>
  <li><code>[4, 4, 1, 1]</code></li>
  <li><code>[3, 3, 3, 1]</code></li>
  <li><code>[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]</code></li>
  <li><code>[4, 3, 1, 1, 1]</code></li>
  <li><code>[4, 3, 3]</code></li>
  <li>. . . (other cases...)</li>
  </ol>
  
  <p>Problem is the code I wrote is breaking after <code>1-3</code> and I'm not sure how to make it loop over the same index to get case <code>4-6+</code></p>
  
  <pre><code>set, sets = [], []
  i = 0
  loop do
  i = 0 if denom_arr[i].nil? 
  
    loop do
      set &lt;&lt; denom_arr[i]
      break if set.inject(:+) &gt; amt
    end
  
    set.pop if set.inject(:+) &gt; amt
  
    if set.inject(:+) == amt
      sets &lt;&lt; set
      set = []
      denom_arr.shift
    end
  
  i += 1
  sets
  break if denom_arr.empty?
  end 
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I know this can be done with recursion with memoization/dynamic programming techniques, but I am trying to do this strictly in a loop for the sake of testing a theory. </p>