This might be useful? I adapted some Python code (somewhat blindly) that generates combinations of a list of values, from here:
The code generates 524K combinations in 3.5 seconds. Then I filter those that add up to 9.
5+4
5+2+2
4+3+2
3+3+3
3+2+2+2
[assign panels_2023Sep5b]
assign panels_2023Sep5b.gh (33.1 KB)
Inserting CSet prior to Split (Text Split) was crucial to improving performance.
Split was producing ~five million results in 3.3 seconds but MA was taking 1.6 minutes …
Combos_2023Dec12a.gh (14.2 KB)
Python:
__author__ = "Joseph Oster"
__version__ = "2021.01.15"
from itertools import combinations
combos = []
for i in range(2,len(vals)+1):
comb = combinations(vals, i)
for c in list(comb):
combos.append("+".join(c))
C = combos
Based on this:
I realized later that my Python struggles with string join ( "+".join(c) ) and converting integers to strings could have been avoided using a ‘Type hint’ of ‘str’ instead of ‘int’. This also makes the code much more flexible since it will work with a list of characters or words as well as integers (or reals?).
This is a simple demo of the modified Combos Python component using characters:
[Combos_2021Jan15a]
Combos_2021Jan15a.gh (10.0 KB)
The slightly simplified Python:
from itertools impo…