Grasshopper

algorithmic modeling for Rhino

Minimum-list-length subset such that mass addition > particular value

I have a set of numbers sorted from smallest to greatest.

I would like to find the first subset of these numbers (starting from the smallest number) such that the Mass Addition (sum) of all these numbers is greater than another, defined number.

 

For instance,

If the set is {1,2,3,4,5,6,7,8,9,10} (typically my numbers are not some sort of typical series, though) and I'm looking for the subset whose sum > 7, I would like to return the subset {1,2,3,4} (since 1 + 2 + 3 + 4 = 10 > 7, so this is the first subset starting at the beginning and working in order whose sum is greater than 7).

 

Is there a way to loop the Mass Addition tool with consecutively larger subsets ( {1} and then {1,2} and then {1,2,3} ), to find the smallest length subset which fulfills this property?  End goal is actually to find the length of this subset, not the subset itself, but a return of either would be fine.

 

Thanks

Views: 1337

Replies to This Discussion

Mass addition does as the Pr output which stands for Partial Results.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service