Solved

# Algorithm to sort numbers into equal groups

Posted on 2009-04-08

I have a process where we are manually trying to sort containers of varying weights into 4 bins of nearest equal total weights. Here is a sample of typical data with 13 items:

1.68

1.76

2.34

3.88

4.04

5.12

6.10

7.00

7.02

7.24

7.68

8.20

8.62

Now I need to determine which items to group into bins. I need 4 bins with the closest matching total weights possible. So in this case the total weight is 70.68. So I need 4 bins containing as close to 17.67/ea. possible. There will always be 4 bins no matter how many items. The total items varies usually between as few as 6 to upwards of 40. Also let me point out that it doesn't matter how many items are in each bin. One bin could have 5 items while another has only 2. We're just trying to match total weights as close as possible.

I'm a VB developer, but can understand most all basic logic as long as it is in somewhat readable form. (why/how explanations help me considerably) I have been working on some basic sorting using arrays, but I'm not able to come up with anything that consistently calculates a best case scenario for different data sets. I need help with an algorithm that will work much more consistently than the manual system we are using now which is for the most part trial and error.