title: Every combination of items in lists
body: <p>My problem is the following : I have a list of N type of product for each type of product I can have a min and a max.</p>
  <p>For exemple :</p>
  <ul>
  <li>Product1 (min: 1, max: 2)</li>
  <li>Product2 (min: 2, max: 3)</li>
  <li>Product3 (min: 1, max: 2)</li>
  </ul>
  <p>Whould give a list like this :</p>
  <pre><code>[
    {Product1}, 
    {Product1, Product1}, 
    {Product2, Product2}, 
    {Product2, Product2, Product2}, 
    {Product3}, 
    {Product3, Product3}
  ]
  </code></pre>
  <p>I now need to do all the combinaison of the possible outputs that will satisfy the constraints of all the products.</p>
  <p>It is straightforward to get the first list and to run the combination function.
  I take the first item in the list, check if it can be merge with the other items in the list, if yes I merge it otherwise nothing is done.
  Once the run is done I call the function recursively with the new list to be computed again until I have no valid combination left.</p>
  <p>For exemple First run would do something like this :</p>
  <ul>
  <li>Product1, Product1, Product1 (invalid)</li>
  <li>Product1, Product2, Product2 (valid)</li>
  <li>Product1, Product2, Product2, Product2 (valid)</li>
  <li>...</li>
  </ul>
  <p>Second run :</p>
  <ul>
  <li>Product1, Product1, Product1, Product1, Product2, Product2 (invalid)</li>
  <li>Product1, Product2, Product2, Product3 (valid)</li>
  <li>...</li>
  </ul>
  <p>With this solution I can correctly compute all my possible combination of products but the perfs for a large amount of possibilities are not that great, I know that my solution involve a lot of loops for invalid combination, to get around 1000 valid combination I test around 400000 of them.</p>
  <p>Is there a way to improve the algorithm to limit the number of test combination ?
  Or do you see an other way of doing it completly differently ?</p>