I know how to create a code in python which actually can allow me to reach the desired number (target) with strings as input, now, what I don’t know how to do is to make this work:

I have a list with dimensions (0.15,0.30,0.45,0.60,0.90,1.20) and I know my target is 0.80.
How can I test the possible combinations of the existing dimensions to make sure that the difference between the target and the optimal combination is minimal?

I am new to Dynamo, so I have not been able to find how to reach the result with Nodes, and as I said before, I though about this on python, but it does not take me to the place i want.

def subset_sum(numbers, target, partial=[]):
s = sum(partial)

# this check if the partial sum is equals to target
if s == target:
print "sum(%s)=%s" % (partial, target)
if s >= target:
return
for i in range(len(numbers)):
n = numbers[i]
remaining = numbers[i+1:]
subset_sum(remaining, target, partial + [n])

You could also use the standard Python itertools module and one of its combinatorial generation method. I posted a few examples of this here (using Python within Grasshopper, but should work exactly the same, except you’ll need to reference the Standard Library):

Hello AndersDeleuran! I tried to script my code using python and it’s now working exactly as i intended, the thing is, I don’t know how to get it to work in Dynamo…

Hello Michael_Kirschner2, I am trying to do it in python and it is currently working when I try to print the results in the console, but, the bad part is that when i try to reproduce it on dynamo, I am having problems defining the variables, would you please help me correct it?

I posted what i am doing on this forum on this particular thread