The problem is a generalization of the folling simple problem:
Given 3 lists of elements, I can loop over the pairings between all 3 lists by folling pseudocode:
foreach( element1 in list1 )
foreach( element2 in list2 )
foreach( element3 in list3 )
dosomething( element1, element2, element3 )
So it will pair an element out of each list with every combination of elements out of the other lists.
Now I have a list of lists of elements, so there are N lists. How can I do the same principle?
My best shot at it so far is to calculate an index for each pairing and iterate over the indices calculated this way:
Let's say the pairing with the first element of every list gets index 0. To illustrate, let's call this {0,0,0,...}. The next index (1) would be {1,0,0,...}. If the first list has size0 elements, the pairing {0,1,0,...} would get index size0. The pairing {2,4,1,0,...} would get index (1*size1 + 4*size0 + 2).
Is there a better way of doing this? Are there languages with this feature built in? Currently I need it in C++, but a general solution is an answer to this question. Language specific implementations can be left in the comments.
using recursion