Given x number of arrays, each with a possibly different number of elements, how can I iterate through all combinations where I select one item from each array?
There's one method I thought of first that uses a couple for loops and no recursion.
Example:
Given A[3], B[2], C[3],
for (index = 0..totalpermutations) {
print A[index % 3];
print B[(index / 3) % 2];
print C[(index / 6) % 3];
}
where of course a for loop can be substituted to loop over [A B C ...], and a small part can be memoized. Of course, recursion is neater, but this might be useful for languages in which recursion is severely limited by stack size.