Random Number List Divide Segments with Sum Threshold

As I needed something simple, a little C#. Just hope there not errors !!


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)

1 Like