I want to divide a data set into four groups such that the sum of elements of each group is approximately same.

for eg: [10, 5, 1, 20, 5, 22, 4, 15]

For the above data set: sum of all the elements = 82

So, I want this data set to be divided into 4 groups such that, the sum of elements of each group is almost same.

One such possibility is

Set 1: 10, 5, 4,1

Set 2: 20

Set 3: 22

Set 4: 15,5

How do I set up this?

An algorithm, C or MATLAB program is highly appreciated

for eg: [10, 5, 1, 20, 5, 22, 4, 15]

For the above data set: sum of all the elements = 82

So, I want this data set to be divided into 4 groups such that, the sum of elements of each group is almost same.

One such possibility is

Set 1: 10, 5, 4,1

Set 2: 20

Set 3: 22

Set 4: 15,5

How do I set up this?

An algorithm, C or MATLAB program is highly appreciated