I have a list of elements:
{{1, 2}, {1, 5}, {2, 6}, {3, 7}, {4, 8}, {5, 6},
{5, 9}, {9, 13}, {10,11}, {11, 12}, {11, 15}, {15, 16}}
I have to divide it into sublists, so that:
#1[[1]] == #2[[1]] || #1[[1]] == #2[[2]] || #1[[2]] == #2[[1]] || #1[[2]] == #2[[2]] &
i.e. at the end I need to obtain:
{{{1, 2}, {1, 5}, {2, 6}, {5, 6}, {5, 9}, {9, 13}},
{3, 7}, {4, 8}, {{10,11}, {11, 12}, {11, 15}, {15, 16}}}
However, I cannot find a solution to do it with Gather
. How can I accomplish this task?
#1
and#2
your sublists? Are there only 2 sublists? As far as I can tell, you want to divide a list of pairs into two 2-length lists where all elements are equal, which makes no sense. You will want to edit your question. $\endgroup$&&
to||
. $\endgroup$