How to create all possible enumerations of multiple arrays

Solution 1:

I think your problem can solved using a recursive algorithm:

Input: arrs (a array of arrays)

Output: combs (array of all possible combinations)

arrs = ??? # this variable provide input arrays, like [[1,2,3], [4,5]]
combs = [] # this variable store the answer 
def get_combs(arrs, i, currentComb):
    if i >= len(arrs):
        combs.append(list(currentComb))
        return
    for elem in arrs[i]:
        currentComb.append(elem)
        get_combs(arrs, i+1, currentComb)
        currentComb.pop()

get_combs(arrs, 0, []) // after this call, the combs get the desired answer.

The code above is in Python and pretty dirty.