So I have a collection of objects, each has a value of either 2 or 4. I’m wanting to group them into collections that equal 12.
For instance, if the collection begins:
[4,4,2] and the next object is 4, I would like to skip and insert a ‘2’ object, leaving the 4 for the next group.
I’ve done some googling and saw someone use shuffle and shift http://stackoverflow.com/questions/22870684/sort-arrays-into-groups-add-remainders-ruby, but this is just grouping to sets of 4 with remainders being evenly distributed.
Any ideas on where to start with this would be most appreciated.
Thanks