Skip to main content
added 681 characters in body
Source Link
Roman
  • 49.9k
  • 2
  • 57
  • 131
lists = {{a, b, c, d}, {i, j, k}, {v, w, x, y, z}};

pairs = Join @@ Tuples /@ Subsets[lists, {2}]
(*    {{a, i}, {a, j}, {a, k}, {b, i}, {b, j}, {b, k}, {c, i},
       {c, j}, {c, k}, {d, i}, {d, j}, {d, k}, {a, v}, {a, w},
       {a, x}, {a, y}, {a, z}, {b, v}, {b, w}, {b, x}, {b, y},
       {b, z}, {c, v}, {c, w}, {c, x}, {c, y}, {c, z}, {d, v},
       {d, w}, {d, x}, {d, y}, {d, z}, {i, v}, {i, w}, {i, x},
       {i, y}, {i, z}, {j, v}, {j, w}, {j, x}, {j, y}, {j, z},
       {k, v}, {k, w}, {k, x}, {k, y}, {k, z}}                    *)

XX = Select[Subsets[pairs, {Length[Flatten[lists]]/2}],
            DuplicateFreeQ@*Flatten]
 
(*    {{{a, i}, {b, v}, {c, w}, {d, x}, {j, y}, {k, z}},
       {{a, i}, {b, v}, {c, w}, {d, x}, {j, z}, {k, y}},
       ...
       {{d, k}, {a, z}, {b, y}, {c, x}, {i, v}, {j, w}},
       {{d, k}, {a, z}, {b, y}, {c, x}, {i, w}, {j, v}}}    *)

There are 1440 such lists X. If you need them in canonical order, they need to be sorted at levels 0, 1, and 2:

XXs = Map[Sort, XX, {0, 2}]
(*    {{{a, i}, {b, v}, {c, w}, {d, x}, {j, y}, {k, z}},
       {{a, i}, {b, v}, {c, w}, {d, x}, {j, z}, {k, y}},
       ...
       {{a, z}, {b, y}, {c, x}, {d, k}, {i, v}, {j, w}},
       {{a, z}, {b, y}, {c, x}, {d, k}, {i, w}, {j, v}}}    *)

in which your original X appears at position 665:

X = {{v, b}, {w, a}, {x, i}, {y, j}, {c, k}, {d, z}};
Position[XXs, Map[Sort, X, {0, 1}]]
(*    {{665}}    *)
lists = {{a, b, c, d}, {i, j, k}, {v, w, x, y, z}};

pairs = Join @@ Tuples /@ Subsets[lists, {2}]
(*    {{a, i}, {a, j}, {a, k}, {b, i}, {b, j}, {b, k}, {c, i},
       {c, j}, {c, k}, {d, i}, {d, j}, {d, k}, {a, v}, {a, w},
       {a, x}, {a, y}, {a, z}, {b, v}, {b, w}, {b, x}, {b, y},
       {b, z}, {c, v}, {c, w}, {c, x}, {c, y}, {c, z}, {d, v},
       {d, w}, {d, x}, {d, y}, {d, z}, {i, v}, {i, w}, {i, x},
       {i, y}, {i, z}, {j, v}, {j, w}, {j, x}, {j, y}, {j, z},
       {k, v}, {k, w}, {k, x}, {k, y}, {k, z}}                    *)

XX = Select[Subsets[pairs, {Length[Flatten[lists]]/2}],
            DuplicateFreeQ@*Flatten]
 
(*    {{{a, i}, {b, v}, {c, w}, {d, x}, {j, y}, {k, z}},
       {{a, i}, {b, v}, {c, w}, {d, x}, {j, z}, {k, y}},
       ...
       {{d, k}, {a, z}, {b, y}, {c, x}, {i, v}, {j, w}},
       {{d, k}, {a, z}, {b, y}, {c, x}, {i, w}, {j, v}}}    *)

There are 1440 such lists X.

lists = {{a, b, c, d}, {i, j, k}, {v, w, x, y, z}};

pairs = Join @@ Tuples /@ Subsets[lists, {2}]
(*    {{a, i}, {a, j}, {a, k}, {b, i}, {b, j}, {b, k}, {c, i},
       {c, j}, {c, k}, {d, i}, {d, j}, {d, k}, {a, v}, {a, w},
       {a, x}, {a, y}, {a, z}, {b, v}, {b, w}, {b, x}, {b, y},
       {b, z}, {c, v}, {c, w}, {c, x}, {c, y}, {c, z}, {d, v},
       {d, w}, {d, x}, {d, y}, {d, z}, {i, v}, {i, w}, {i, x},
       {i, y}, {i, z}, {j, v}, {j, w}, {j, x}, {j, y}, {j, z},
       {k, v}, {k, w}, {k, x}, {k, y}, {k, z}}                    *)

XX = Select[Subsets[pairs, {Length[Flatten[lists]]/2}],
            DuplicateFreeQ@*Flatten]
(*    {{{a, i}, {b, v}, {c, w}, {d, x}, {j, y}, {k, z}},
       {{a, i}, {b, v}, {c, w}, {d, x}, {j, z}, {k, y}},
       ...
       {{d, k}, {a, z}, {b, y}, {c, x}, {i, v}, {j, w}},
       {{d, k}, {a, z}, {b, y}, {c, x}, {i, w}, {j, v}}}    *)

There are 1440 such lists X. If you need them in canonical order, they need to be sorted at levels 0, 1, and 2:

XXs = Map[Sort, XX, {0, 2}]
(*    {{{a, i}, {b, v}, {c, w}, {d, x}, {j, y}, {k, z}},
       {{a, i}, {b, v}, {c, w}, {d, x}, {j, z}, {k, y}},
       ...
       {{a, z}, {b, y}, {c, x}, {d, k}, {i, v}, {j, w}},
       {{a, z}, {b, y}, {c, x}, {d, k}, {i, w}, {j, v}}}    *)

in which your original X appears at position 665:

X = {{v, b}, {w, a}, {x, i}, {y, j}, {c, k}, {d, z}};
Position[XXs, Map[Sort, X, {0, 1}]]
(*    {{665}}    *)
added 419 characters in body
Source Link
Roman
  • 49.9k
  • 2
  • 57
  • 131
lists = {{a, b, c, d}, {i, j, k}, {v, w, x, y, z}};

pairs = Join @@ Tuples /@ Subsets[lists, {2}]
(*    {{a, i}, {a, j}, {a, k}, {b, i}, {b, j}, {b, k}, {c, i},
       {c, j}, {c, k}, {d, i}, {d, j}, {d, k}, {a, v}, {a, w},
       {a, x}, {a, y}, {a, z}, {b, v}, {b, w}, {b, x}, {b, y},
       {b, z}, {c, v}, {c, w}, {c, x}, {c, y}, {c, z}, {d, v},
       {d, w}, {d, x}, {d, y}, {d, z}, {i, v}, {i, w}, {i, x},
       {i, y}, {i, z}, {j, v}, {j, w}, {j, x}, {j, y}, {j, z},
       {k, v}, {k, w}, {k, x}, {k, y}, {k, z}}                    *) 

XX = Select[Subsets[pairs, {Length[Flatten[lists]]/2}],
            DuplicateFreeQ@*Flatten]

(*    {{{a, i}, {b, v}, {c, w}, {d, x}, {j, y}, {k, z}},
       {{a, i}, {b, v}, {c, w}, {d, x}, {j, z}, {k, y}},
       ...
       {{d, k}, {a, z}, {b, y}, {c, x}, {i, v}, {j, w}},
       {{d, k}, {a, z}, {b, y}, {c, x}, {i, w}, {j, v}}}    *)

There are 1440 such lists X.

lists = {{a, b, c, d}, {i, j, k}, {v, w, x, y, z}};

Join @@ Tuples /@ Subsets[lists, {2}]
(*    {{a, i}, {a, j}, {a, k}, {b, i}, {b, j}, {b, k}, {c, i},
       {c, j}, {c, k}, {d, i}, {d, j}, {d, k}, {a, v}, {a, w},
       {a, x}, {a, y}, {a, z}, {b, v}, {b, w}, {b, x}, {b, y},
       {b, z}, {c, v}, {c, w}, {c, x}, {c, y}, {c, z}, {d, v},
       {d, w}, {d, x}, {d, y}, {d, z}, {i, v}, {i, w}, {i, x},
       {i, y}, {i, z}, {j, v}, {j, w}, {j, x}, {j, y}, {j, z},
       {k, v}, {k, w}, {k, x}, {k, y}, {k, z}}                    *)
lists = {{a, b, c, d}, {i, j, k}, {v, w, x, y, z}};

pairs = Join @@ Tuples /@ Subsets[lists, {2}]
(*    {{a, i}, {a, j}, {a, k}, {b, i}, {b, j}, {b, k}, {c, i},
       {c, j}, {c, k}, {d, i}, {d, j}, {d, k}, {a, v}, {a, w},
       {a, x}, {a, y}, {a, z}, {b, v}, {b, w}, {b, x}, {b, y},
       {b, z}, {c, v}, {c, w}, {c, x}, {c, y}, {c, z}, {d, v},
       {d, w}, {d, x}, {d, y}, {d, z}, {i, v}, {i, w}, {i, x},
       {i, y}, {i, z}, {j, v}, {j, w}, {j, x}, {j, y}, {j, z},
       {k, v}, {k, w}, {k, x}, {k, y}, {k, z}}                    *) 

XX = Select[Subsets[pairs, {Length[Flatten[lists]]/2}],
            DuplicateFreeQ@*Flatten]

(*    {{{a, i}, {b, v}, {c, w}, {d, x}, {j, y}, {k, z}},
       {{a, i}, {b, v}, {c, w}, {d, x}, {j, z}, {k, y}},
       ...
       {{d, k}, {a, z}, {b, y}, {c, x}, {i, v}, {j, w}},
       {{d, k}, {a, z}, {b, y}, {c, x}, {i, w}, {j, v}}}    *)

There are 1440 such lists X.

Source Link
Roman
  • 49.9k
  • 2
  • 57
  • 131

lists = {{a, b, c, d}, {i, j, k}, {v, w, x, y, z}};

Join @@ Tuples /@ Subsets[lists, {2}]
(*    {{a, i}, {a, j}, {a, k}, {b, i}, {b, j}, {b, k}, {c, i},
       {c, j}, {c, k}, {d, i}, {d, j}, {d, k}, {a, v}, {a, w},
       {a, x}, {a, y}, {a, z}, {b, v}, {b, w}, {b, x}, {b, y},
       {b, z}, {c, v}, {c, w}, {c, x}, {c, y}, {c, z}, {d, v},
       {d, w}, {d, x}, {d, y}, {d, z}, {i, v}, {i, w}, {i, x},
       {i, y}, {i, z}, {j, v}, {j, w}, {j, x}, {j, y}, {j, z},
       {k, v}, {k, w}, {k, x}, {k, y}, {k, z}}                    *)