Skip to main content
1 of 2
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

Adapting Heike's fine answer from the prior question:

pairs //. x_ :> Union @@@ Gather[x, # ⋂ #2 =!= {} &]
{{1, 6, 10, 13, 36},
 {12, 14, 16, 23},
 {11, 21, 22, 35},
 {3, 5,  9},
 {17, 20, 24, 25, 28, 32},
 {4, 7, 19, 26, 30, 33, 34},
 {2, 8, 15, 18, 27, 29, 31}}
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k