algorithmic modeling for Rhino
Say I have a list as follows:
and I want to get every possible combination that does not necessarily use all the indices. Essentially I want a tree that would look like this:
Can cross reference be used to produce a tree like this?
Yes it is possible, but convoluted and inefficient:
Convoluted because obvious, inefficient because on your way to the answer you end up calculating ALL possible combinations, which is a much larger set.
The general idea being:
Oops, forgot to attach the file.
Thanks David. This next question might shed too much light on my lacking math skills, but let's say I'm dealing with a much larger set of words and the number of permutations is less obvious. What is the formula for calculating the number of possible pemutations. I know the basic formala is n^r. But in the case the formula needs to be solved with r=n... r=1. Something tells me this is obvious and I'm not seeing it...
Yes I can see now how this can be a inefficient way to solve this problem. It seems like when dealing with 12 source words the number of possible permutations is too high for grasshopper to handle.
Yup, it blows up pretty damn quick.
It is fun thinking about this. I came up with an algorithm which is reasonably efficient, though not particularly elegant. It sometimes generates duplicate entries so it must deal with those which costs additional processor cycles.
It generates an index map which can then be used to retrieve the actual items. Code is heavily annotated, but pretty thorny nonetheless.
The basic idea is that you start with a complete pattern containing all elements, then you recursively remove elements from that pattern, generating all the patterns that are one item shorter. Then you recursively remove individual elements from this new list of shorter patterns to create shorter patterns still. Repeat until the pattern length drops below 1.
The problem is that if you first remove 'B' from 'A,B,C,D' and then remove 'D', you end up with the same pattern as when you first remove 'D' and then 'B'. So these cases need to be tested. I'm sure there's some clever looping that just does the right thing, but I couldn't think of it.
Thanks Peter this definitely works except for one minor thing. In my specific case order does not matter. It seems your script has the added bonus of finding the permutations when order does matter which, in my case, results in duplicate branches.
my 5th virsion (latest post) is the fastest as it uses anemone fast loop
but Anders version with python is very good
but its good example because in the beginning it also show you how many possible permutations/combinations even for higher values without producing the results