Thread: creating combinations of array values - recursion??

1. creating combinations of array values - recursion??

I have about 10 arrays (this number is a variable, can be more or less) with a certain number of elements in each (again number fo elements can vary for each array).

I need to create all combinations of these arrays.
A simple ex:

Array1: 1,2
Array2: 4
Array3: 5,6

Output should be

1 4 5
1 4 6
2 4 5
2 4 6

Would recusion be a good way of doing it?
Or is there any other approach?

2. Recursion can work if you can come up with a base function that can be implemented to traverse your arrays to determine the unique combinations there of.

What appears, from the surface, is that you have/need some sort of graphing algorithm that can be put together in how these arrays relate to one another. This will determin if array1 element 1 can be related/connected in some fashion to array3 element 6.

A simple means of using for loops can to the job.

The big question is what have you come up with as far as code?

3. Recursion is a very easy way of doing this. Though a loop seems like an even easier and more stack friendlier method.