On doing CodingBat's MakeBricks problem, I realised the following might work for a definitive (non-random, guarenteed minimal difference for unlimited collection size) of the Divvier program (though original would still have some notional utility in that it generates alternative divisions, some of which might also be exact minimal diff)...
Where total = sum of values and halfTotal = half that, want abs(h - minDiff) minimal (as before)
First sort the collection by value of elements: z, y, x... in descending order (z >= y, y >= x etc)
There may be duplicate/replicate values, e.g. z = y, so then make a Map for easier processing
i.e. value-frequency pairs e.g. z:2, x:1 ...
If z < halfTotal, add as many z's as possible for sum < h
(stop when you run out of z's or exceed halfTotal-1)
Decrement the frequency in the Map for each addition, i.e z:2 becomes z:1 and then z:0
(Also make a reciprocal Map)
(If z >= halfTotal already, solution is just z vs the rest of the collection)
Then add as many of the next value as possible in the same manner
(and if adding a single one would exceed halfTotal, add none)
Then repeat for each sucessive value (until halfTotal-1 exceeded)
Convert the two (reciprocal) maps to collections of the original type for return/reporting