Attention |
Topic was automatically imported from the old Question2Answer platform. | |

Asked By |
blurymind | |

Old Version |
Published before Godot 3 was released. |

Basically I am trying to write a function in gdscript that returns an array of all possible combinations of a sequence of numbers.

something similar to this:

Class1 = [1,2,3,4] Class2 = [1,2,3,4] Class3 = [1,2,3,4]

Now what I would like to do is return all possible combinations of

these three classes.Example:

1 1 1

2 1 1

3 1 1

4 1 1

1 2 1

2 2 1

3 2 1

4 2 1…

**In my case the number of classes and the number of items in each class varies**

The top answer for this is:

```
import itertools
iterables = [ [1,2,3,4], [88,99], ['a','b'] ]
for t in itertools.product(*iterables):
print t
```

Looking at itertools, this is how the product function there looks like:

```
def product(*args, repeat=1):
# product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
# product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
pools = [tuple(pool) for pool in args] * repeat
result = [[]]
for pool in pools:
result = [x+[y] for x in result for y in pool]
for prod in result:
yield tuple(prod)
```

Can you guys please help me somehow get this functionality translated to gdscript please?

I am really struggling with this one!