# All combinations in a tree

Hi,

I’m a beginner with Grasshopper and new in this forum. I have a problem with the combination of tree data.

I have a tree with a variable amount of branches. In each branch, there are 32 breps. Each branch stands for one point. So I have “n” points with 32 variantens of breps. Now I would like to combine one item (means one variation of brep) of the first branch with one item of the second branch and so on.
Easy said, I’m searching all combinations that are possible if I only take one item out of each branch.
My goal is to have all possible variations of combinating the breps, but only with one brep at each point.
I know that this will produce a enormously high amount of variations.

I tried to solve it with Cross Reference, but the only way I could do this is extremly impractical with a loop and Hoopsnake. My problem is that I dont know how to use cross reference on many branches at the same time. And because of the variable amount of points (branches) I cant do it by hand and connect branch 1 and 2 with cross reference, the result with branch 3 etc. I dont even know how to start to solve this problem.

It would be super helpful if you could give me some tips.

As long as the number of branches if equal to or less than 3, then the possible number of combinations is still manageable. If you have four branches you’ll end up with 32^4 \approx one-million, five branches gives you 32^5 \approx thirty-three-million.

If I understand correctly, you have a tree with n branches, and each branch has 32 values:

\left(a_0, a_1, a_2, \ldots, a_{31}\right), \left(b_0, b_1, b_2, \ldots, b_{31}\right), \ldots , \left(n_0, n_1, n_2, \ldots, n_{31}\right)

And you want a tree which has 32^n branches, where each branch contains n values:

\left(a_0, b_0, \ldots, n_0 \right), \left(a_0, b_0, \ldots, n_1 \right), \left(a_0, b_0, \ldots, n_2 \right), \ldots, \left(a_2, b_8, \ldots, n_6 \right), \ldots, \left(a_{31}, b_{31}, \ldots, n_{31} \right)

I don’t think I’m confused by your description, but just making sure I’m not.

Yes, you’ve got the problem right. I will reduce the items in the branches with filters before, so that the number of combinations isn’t that high.

That was not easy. As far as I know the Char Sequence component is the only one that will generate something like a set of combinations. It doesn’t do it exactly the way it’s needed, but maybe this will help you on your way: combinations.gh (32.6 KB)

Oh wow, thanks a lot David! I would never have come to that!