Want to subdivide a list of random numbers so that within the subdivided partitions the sum of the numbers is as close to but not above an adjustable threshold. In practice the threshold would always be greater than the largest random number. For example:
Take a random list of numbers:
4
2
11
2
1
6
3
6
2
5
1
4
8
7
Subdivide to several lists with a maximum sum threshold.
DataTree output = new DataTree();
int sum = 0;
int path = 0;
foreach(int val in x)
{
if ((sum + val) > limit)
{
sum = 0;
path += 1;
}
sum = sum + val;
output.Add(val, new GH_Path(path));
}
A = output; limit int addition.gh (14.7 KB)