This is an interesting problem. I will use your example by dividing the numbers 1..10 into three groups to illustrate my answer. The solution will apply to any set of numbers and any number of groups. From sources, when the size of a set of numbers is large, you cannot use the brute force method. Having said that, large numbers can be processed in a similar way, but more on that later.
Suppose we have M consecutive numbers, indicated by (1..M), in a set, and we want to divide them into N groups.
The first thing to determine is the value that you will compare with the sum of each group. This is simply the sum of a set of numbers divided by the number of groups N.
In the example, sumOf (1..M) = 55 and N = 3, so 55/3 = 18.33 is the value that each group should sum. You want to minimize the difference between the sums of groups and 18.33
As another example, if you want to divide the set of numbers 1..20 into two groups, you need to minimize the difference between the sums of the groups and divide sumOf (1..20) = 210 into 2 groups = 210/2 = 105.
The next step is to find all possible groups. This is another interesting problem, given the limitation of profiles containing consecutive numbers, the total number of combinations of groups is not as many as you might expect.
Finding combinations is a recursive task, and itβs easy enough to work out a general equation.
lets start with a simple case. How many combinations of 10 numbers in the set (1..10). Well, there is only one group, numbers (1..10)
Now, how many combinations of 2 groups in 10 numbers. The answer is M-1 or 10-1 = 9, namely
(1),(2..10) (1..2) (3..10) (1..3) (4..10) (1..4) (5..10) (1..5) (6..10) (1..6) (7..10) (1..7) (8..10) (1..8) (9..10) (1..9) (10)
Thus, the size set M has combinations of groups M-1. This is the basis of recursion.
How many combinations of 3 groups in 10 numbers.
Well, the first group will be one of the following
(1),(1..2),(1..3) ,(1..4) ,(1..5),(1..6) ,(1..7) ,(1..8)
Given any of them as the first group, let's find out how many combinations of 2 groups exist in the remaining numbers.
Let the first group of three = (1). We have nine numbers left and they can make 9-1 = 8 different combinations of 2 groups. Let the first group of three = (1..5). We have five numbers left, and they can make 5-1 = 4 different groups of 2 numbers.
So overall we will have
(1) -> 8 combinations (1..2) -> 7 combinations (1..3) -> 6 combinations (1..4) -> 5 combinations (1..5) -> 4 combinations (1..6) -> 3 combinations (1..7) -> 2 combinations (1..8) -> 1 combinations
giving SumOf (1..8) or in general (sum (1..M-2), combinations of groups. SumOf (1..8) = 8 * 9/2 = 36
Thus, there are 36 combinations of 3 groups of 10 numbers, where each group contains consecutive numbers.
as an aside, for 3 groups of 100 numbers you have sumOf (1..98) = 98 * 99/2 = 4851 combinations of groups, as M increases, you get more combinations and as some value of M the brute force method is impossible.
The above approach can be used to develop a simple recursive algorithm for obtaining all combinations of groups in the set (1..M).
In addition, for any number N of groups in the set of numbers M, a simple equation can be developed. For example, if you move to 4 groups of 10 numbers, then you have situations, such as the first group (1..3), and then find combinations of 3 groups in the remaining 7 numbers. There will be a sum (1..M-2) = a sum (1..5), etc.
In any case, back to the problem. You have all the combinations of groups, and you can iterate through the groups and calculate the SAD for each combination and choose the one that minimizes the SAD.
When the number of combinations is very large, and you cannot look at each combination, then you can try self-tuning to select groups in a random or some evolutionary algorithm approach, in which you start with the number of randomly selected combinations, and then randomly move numbers from one group to another and keep those with the lowest SAD. Continue this step until you see an improvement in the GARDEN.
Or you can do as @Robert King suggested, starting with one combination and improving it by moving numbers from one group to another.