Re: Faster ways to unionize intersecting sets?
- To: mathgroup at smc.vnet.net
- Subject: [mg70299] Re: Faster ways to unionize intersecting sets?
- From: Peter Pein <petsie at dordos.net>
- Date: Thu, 12 Oct 2006 05:37:14 -0400 (EDT)
- References: <eg02a3$81m$1@smc.vnet.net> <eg2e4o$70u$1@smc.vnet.net> <eg81ph$mqh$1@smc.vnet.net>
lsha schrieb: > Hi, > > I tried mergeSets2[] and the answer is different from mergeSets[]. > An example: > In[34]:= > s = {{1, 2}, {2, 3}, {4, 5}, {6, 7}, {7, 5}, {9, 10}, {11, 12}, {13, 14}}; > > > In[35]:= > mergeSets[s] > Out[35]= > {{1, 2, 3}, {4, 5, 6, 7}, {9, 10}, {11, 12}, {13, 14}} > > > In[36]:= > mergeSets2[s] > Out[36]= > {{{9, 10}, {11, 12}, {13, 14}}, {1, 2, 3, 4, 5, 6, 7}} > > The non-intersecting singles are correct but the intersecting sets are all > merged together with mergeSets2[]. > > Regards, > Ling Sha > Hi, just my 2 cents: s={{1,2},{2, 3},{4, 5},{6,7},{7,5},{9,10},{11,12},{13,14}}; s//.{a___,x_List,b___,y_List,c___}/;Intersection[x,y]=!={}:>{a,Union[x,y],b,c} --> {{1, 2, 3}, {4, 5, 6, 7}, {9, 10}, {11, 12}, {13, 14}} Peter