Given a list lists
:
lists={{{1, 2}, {3, 4}, {5, 6}}, {{1, 2}, {3, 5}, {4, 6}}, {{1, 2}, {3, 6}, {4, 5}},
{{1, 3}, {2, 4}, {5, 6}}, {{1, 3}, {2, 5}, {4, 6}}, {{1, 3}, {2, 6}, {4, 5}},
{{1, 4}, {2, 3}, {5, 6}}, {{1, 4}, {2, 5}, {3, 6}}, {{1, 4}, {2, 6}, {3, 5}},
{{1, 5}, {2, 3}, {4, 6}}, {{1, 5}, {2, 4}, {3, 6}}, {{1, 5}, {2, 6}, {3, 4}},
{{1, 6}, {2, 3}, {4, 5}}, {{1, 6}, {2, 4}, {3, 5}}, {{1, 6}, {2, 5}, {3, 4}}};
I would like to get the following results:
results={
{{{1, 2}, {3, 4}, {5, 6}}, {{1, 3}, {2, 5}, {4, 6}}, {{1, 4}, {2, 6}, {3, 5}}, {{1, 5}, {2, 4}, {3, 6}}, {{1, 6}, {2, 3}, {4, 5}}},
{{{1, 2}, {3, 4}, {5, 6}}, {{1, 3}, {2, 6}, {4, 5}}, {{1, 4}, {2, 5}, {3, 6}}, {{1, 5}, {2, 3}, {4, 6}}, {{1, 6}, {2, 4}, {3, 5}}},
{{{1, 2}, {3, 5}, {4, 6}}, {{1, 3}, {2, 4}, {5, 6}}, {{1, 4}, {2, 5}, {3, 6}}, {{1, 5}, {2, 6}, {3, 4}}, {{1, 6}, {2, 3}, {4, 5}}},
{{{1, 2}, {3, 5}, {4, 6}}, {{1, 3}, {2, 6}, {4, 5}}, {{1, 4}, {2, 3}, {5, 6}}, {{1, 5}, {2, 4}, {3, 6}}, {{1, 6}, {2, 5}, {3, 4}}},
{{{1, 2}, {3, 6}, {4, 5}}, {{1, 3}, {2, 4}, {5, 6}}, {{1, 4}, {2, 6}, {3, 5}}, {{1, 5}, {2, 3}, {4, 6}}, {{1, 6}, {2, 5}, {3, 4}}},
{{{1, 2}, {3, 6}, {4, 5}}, {{1, 3}, {2, 5}, {4, 6}}, {{1, 4}, {2, 3}, {5, 6}}, {{1, 5}, {2, 6}, {3, 4}}, {{1, 6}, {2, 4}, {3, 5}}}
}
Notice that for every subsets (i.e. results[[1]]
), there are no repeated elements (i.e. {1, 2}
) and every subsets contains the maxmum elements.
When lists={{{1, 2}, {3, 4}}, {{1, 3}, {2, 4}}, {{1, 4}, {2, 3}}}
, we can easily have results={{{{1, 2}, {3, 4}}, {{1, 3}, {2, 4}}, {{1, 4}, {2, 3}}}}
. Here is the example code which seems only works for n=4:
n = 4;
lists = Select[Subsets[Subsets[Range[n], {2}], {Length[Range[n]]/2}],
DuplicateFreeQ@*Catenate];
results = {};
res = {};
For[i = 1, i <= Length[lists], i++,
AppendTo[results, SortBy[res, First]];
res = {};
AppendTo[res, lists[[i]]];
For[j = 1, j <= Length[lists], j++,
If[DisjointQ[lists[[i]], lists[[j]]],
If[Length[res] <= 1,
AppendTo[res, lists[[j]]];,
If[DisjointQ[Flatten[res, 1], lists[[j]]], AppendTo[res, lists[[j]]];];
];
];
];
];
results = DeleteDuplicates[DeleteCases[results, {}]];
len = Length[results];
Questions:
- Is there a simple way to do the above task? How to do the above task for
n=6
? - When
n
goes large, my code doesn't work (i.e.n=8
,len
should be 6240; see A000438). Is there a systematically way?
Thank you very much in advance! Any hints or suggestions are appreciated!