-1

How to you generate a set of all possible 1-1 mappings between two lists. I want each mapping to be unique, but am not too concerned about computation time (brute force is probably fine). Lists can be different sizes, or we can just fill in the shorter list with nulls.

Example:
List A = [x, y] (or [x, y, null])
List B = [1, 2, 3] 

Results would be something like:
[[1x,2y,3],
[1x,2,3y],
[1y,2x,3],
[1y,2,3x],
[1,2y,3x],
[1,2x,3y]]

Is there a simple way to do this (preferably in Java)? The lists can be any size (and different sizes).

Thanks

1 Answers1

0

Your expected output is basically just a combination of List A with all possible permutations of List B.

listPermutations
    input: list a , list b

    list result

    //add nulls to b until b reaches the length of a
    extend(b , length(a))

    for list p in permutations(b)
        add(result , combine(a , p))

    return result