Skip to main content
deleted 51 characters in body
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k

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[[1]] || #1[[1]] == #2[[2]]&&#1[[2]]#2[[2]] || #1[[2]] == #2[[1]]&&#1[[2]]#2[[1]] || #1[[2]] == #2[[2]] &

i.e. at the end I mightneed 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. Did anybody have such problems How can I accomplish this task? Hope to hear from you nice advices.... Thanks in advance!

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 might 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. Did anybody have such problems? Hope to hear from you nice advices.... Thanks in advance!

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?

edited tags
Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k
edited tags; edited title
Link
István Zachar
  • 47.2k
  • 20
  • 145
  • 293

Using GATHER in MathematicaGather to rearrange my data

Post Migrated Here from stackoverflow.com (revisions)
Source Link
Loading