Formula to calculate distribution of numbers to be grouped

16 Views Asked by At

Firstly.. I'm not a mathematician and I apologise upfront if this question is posted in the wrong area.

I have the following scenario. I have a bulk of boxes with Box number (such as box1, box2,box3,box4,...) and Box weight such as (Box1 is 2.5kg, Box2 is 6.8kg, Box3 is 9.7kg, ...)

I need regroup these bulk box with given maximum weight (kg) for each group. For example, the maximum of weight for each group is 15kg. Therefore, system has to calculate to take all possibility boxes with total weight no more than 15kg and place it into the least amount of groups.

So lets take a simple example and work with 5 kgs per group

Box#    Weight  
1       1.5  
2       3  
3       1  
4       2.5  
5       2.5  
6       1.5  
7       2  
8       3  

This becomes:

Group 1
Box # Weight  
7     2
8     3

Group 2
1     1.5
3     1
4     2.5

Group 3
5     2.5  
6     1.5

Group 4
2     3 

Now my task is to currently convert the problem to a software program. I would appreciate it if anyone can assist with a formula of some sorts to help solve the problem or point me in a right direction to a solution.