title: Algorithm to evenly distribute values into containers?
body: <p>Does anyone know a way to evenly distribute numbers into a set number of containers, making sure that the total values of the containers are as even as possible?</p>
  
  <p>EDIT: by "even as possible" I mean that the total of each container will be as close to the total average if distributed in X amount of containers.</p>
  
  <p>Right now I simply sort the array of numbers(descending) and then distribute them, oblivious of their value, into the containers. A set of 1000, 200, 20, 1000 distributed into three containers would equal [2000], [200], [20].</p>
  
  <p>What I want to do is:</p>
  
  <pre><code>Example
  
  Set of numbers: 10 30 503 23 1 85 355
  If I were to distribute these into three containers I would just pick the highest first and then distribute them as I go, like this:
  Cont 1 = 503
  Cont 2 = 355
  Cont 3 = 85 + 30 + 23 + 10 + 1
  
  This will give the best possible distribution that you can get with the values provided.
  </code></pre>
  
  <p>But I do not know of a neat way to express this in code.</p>
  
  <p>Ideas?</p>