Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Match Pairs of Numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86900] Re: [mg86879] Match Pairs of Numbers
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Wed, 26 Mar 2008 04:47:27 -0500 (EST)
  • Reply-to: hanlonr at cox.net

lst = {{1, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 2}, {3, 1}, {3, 2}, {3, 
    3}, {4, 1}, {4, 4}};

Select[lst, MemberQ[DeleteCases[lst, #], Reverse[#]] &]

{{1, 3}, {1, 4}, {3, 1}, {4, 1}}

Cases[lst, _?(MemberQ[DeleteCases[lst, #], Reverse[#]] &)]

{{1, 3}, {1, 4}, {3, 1}, {4, 1}}

DeleteCases[lst, _?(FreeQ[DeleteCases[lst, #], Reverse[#]] &)]

{{1, 3}, {1, 4}, {3, 1}, {4, 1}}

Pick[lst, MemberQ[DeleteCases[lst, #], Reverse[#]] & /@ lst]

{{1, 3}, {1, 4}, {3, 1}, {4, 1}}


Bob Hanlon

---- Andrew Beveridge <acbev at lanl.gov> 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
> 
> 



  • Prev by Date: Re: Tagged list processing
  • Next by Date: Limit[(x - Log[Cosh[x]]) SinIntegral[x], x -> Infinity]
  • Previous by thread: Re: Match Pairs of Numbers
  • Next by thread: Re: Match Pairs of Numbers