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?
Comments
Post a Comment