I have a text file like this:
A
B
C
And each element has a subset like this:
A = { a1, a2, a3 }
B = { b1, b2 }
C = { c1, c2, c3 }
I want to generate this:
a1, b1, c1
a2, b1, c1
a3, b1, c1
a1, b2, c1
a1, b1, c2
a1, b1, c3
I don’t know the number of elements in the text file (e.g. could be: A, B, C, D, E) and the subsets could vary in size.
All I can think it’s a recursive function with 2 indexes, maybe “position in the array” and “index of the array”, but I really don’t know how to implement all of this.
I even tried to adapt a function that does cartesian product with the same inputs, but I totally failed. I don’t need to generate Cartesian product.
Loop through all the lists where the index is the list to be iterated.
Find the size of the inner List to be iterated and loop that many time.
Loop through the lists always getting the first element unless the list is the list being indexed, in which case get the next value from the iteration list.