title: Dividing elements of a ruby array into an exact number of (nearly) equal-sized sub-arrays
body: <p>I need a way to split an array in to an exact number of smaller arrays of roughly-equal size. Anyone have any method of doing this?</p>
  <p>For instance</p>
  <pre><code>a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] 
  groups = a.method_i_need(3)
  groups.inspect
      =&gt; [[1,2,3,4,5], [6,7,8,9], [10,11,12,13]]
  </code></pre>
  <blockquote>
  <p>Note that this is an entirely separate problem from <a href="https://stackoverflow.com/q/1230279/2063546">dividing an array into chunks</a>, because <code>a.each_slice(3).to_a</code> would produce 5 groups (not 3, like we desire) and the final group may be a completely different size than the others:</p>
  <pre><code>[[1,2,3], [4,5,6], [7,8,9], [10,11,12], [13]]  # this is NOT desired here.
  </code></pre>
  </blockquote>
  <p>In this problem, the desired number of chunks is specified in advance, and the sizes of each chunk will differ by 1 at most.</p>