Re: Match Pairs of Numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg86910] Re: [mg86879] Match Pairs of Numbers
- From: Curtis Osterhoudt <cfo at lanl.gov>
- Date: Wed, 26 Mar 2008 04:51:49 -0500 (EST)
- Organization: LANL
- References: <200803250614.BAA10496@smc.vnet.net>
- Reply-to: cfo at lanl.gov
Greetings from MPA-11! The following will hopefully do what you want, though the resulting list isn't sorted into the pairs: lst = {{1, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 2}, {3, 1}, {3, 2}, {3, 3}, {4, 1}, {4, 4}}; In[4]:= Select[ Intersection[lst, Reverse /@ lst], #1[[1]] != #1[[2]] & ] Out[4]= {{1, 3}, {1, 4}, {3, 1}, {4, 1}} This forms the intersection of the list of pairs and the reversed pairs (keeping only those elements which are present both forwards and backwards), and then Select chooses those elements which don't have both numbers the same in each pair (e.g. {1,1} leaves, as does {2,2}, etc.). Regards, C.O. On Tuesday 25 March 2008 00:14:52 Andrew Beveridge wrote: > Any help would be appreciated. > > I am using Mathematica 5.2 & 6.0 > > I am having trouble finding the correct form of Pattern Matching for > pairs of Numbers. I do not know whether to use Select, Cases, Pick, > etc. I am also unsure how to set the pattern matching argument. > > Assume I have the list > > lst = {{1,1}, {1,2}, {1,3}, {1,4}, {2,2}, {3,1}, {3,2}, {3,3}, {4,1}, > {4,4}} > > > I would like to match/select pairs that have the same set of numbers > only reversed, that is, the selection would find > > {{1,3}, {3,1}, {1,4}, {4,1} } > > Thanks for your help > > > Andrew C Beveridge > MS M888 > Los Alamos National Laboratory > Los Alamos, NM 87545 > > 505-665-2092 > e-mail: acbev at lanl.gov -- ========================================================== Curtis Osterhoudt cfo at remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html ==========================================================
- References:
- Match Pairs of Numbers
- From: Andrew Beveridge <acbev@lanl.gov>
- Match Pairs of Numbers