title: Packing item from set of available packs
body: <p>Suppose there is an <strong>Item</strong> that a customer is ordering - in this case it turns out they are ordering 176 (<code>totalNeeded</code>) of this <strong>Item</strong>.</p>
  
  <p>The database has 5 records associated with this item that this item can be stored in:</p>
  
  <p><code>{5 pack, 8 pack, 10 pack, 25 pack, 50 pack}</code>.</p>
  
  <p>A rough way of packing this would be:</p>
  
  <pre><code> Sort the array from biggest to smallest.
  
   While (totalPacked &lt; totalNeeded) // 176
        {
           1. Maintain an &lt;int, int&gt; dictionary which contains Keys of pack id's, 
           and values of how many needed
  
           2. Add the largest pack, which is not larger than the amount remaining to pack, 
           increment totalPacked by the pack size
  
           3. If any remainder is left over after the above, add the smallest pack to reduce 
           waste
                 e.g., 4 needed, smallest size is 5, so add one 5; one extra item packed
        }
  </code></pre>
  
  <p>Based on the above logic, the outcome would be:</p>
  
  <p><strong>You need</strong>: 3 x 50 packs, 1 x 25 pack, 1 x 5 pack</p>
  
  <p><strong>Total Items</strong>: 180</p>
  
  <p><strong>Excess</strong> = 4 items; 180 - 176</p>
  
  <p>The above is not too difficult to code, I have it working locally. However, it is not truly the best way to pack this item. Note: "best" means, smallest amount of excess.</p>
  
  <p>Thus ... we have an 8 pack available, we need 176. 176 / 8 = 22. Send the customer 22 x 8 packs, they will get exactly what they need. Again, this is even simpler than the pseudo-code I wrote ... see if the total needed is evenly divisible by any of the packs in the array - if so, "at the very least" we know that we can fall back on 22 x 8 packs being exact.</p>
  
  <p>In the case that the number is not divisible by an array value, I am attempting to determine possible way that the array values can be combined to reach at least the number we need (176), and then score the different combinations by # of Packs needed total.</p>
  
  <p>If anyone has some reading that can be done on this topic, or advice of any kind to get me started it would be greatly appreciated.</p>
  
  <p>Thank you</p>