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

Grasshopper Question sorting numbers in a List.gh (18.3 KB)

Hello,

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:

missing

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


numbers_2023May18a.gh (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.

Combinations_Sums_V1A.gh (128.9 KB)