Sort a list in lists in which the sum of the numbers ≤ set value

Grasshopper Question sorting numbers in a (18.3 KB)


i’ve tried some python scripts from different questions, but they don’t quite solve the problem and i have no python experience. I don’t know if you can do it only in grasshopper.

I want to sort all the 21 numbers in the picture above in lists were the sum doesnt exceed 240 but still gets as close as possible. the list length and the total amount of those (max 240) lists necessary doesn’t matter.

Hope it was clear enough

Lot’s of similar topics around. Like:


I’m sure you can, though this example might not be the best answer. (19.6 KB)

By the way, running data through text panels is generally a bad idea. They are great for examining component outputs but can cause data corruption in certain cases.

ok thanks for the help joseph!

That’s a tough cookie (if we are after “ideal/best” solutions AND we invite combinations/permutations to the party … we are talking O(2^n) solution … meaning the obvious: Adios Amigos),

Anyway a simplistic (a bit naive) solution could be (you can’t translate C# to P [plus: I hate P]):

BTW: Don’t attempt to solve that without code.

@PeterFotiadis Hello Peter, would be great if you share the script

Get this (but is a typical O[2^N] comb solution … meaning the obvious). So handle with extreme care. (128.9 KB)