MathGroup Archive 2008

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

Search the Archive

Re: Match Pairs of Numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86921] Re: [mg86879] Match Pairs of Numbers
  • From: János <janos.lobb at yale.edu>
  • Date: Wed, 26 Mar 2008 04:53:57 -0500 (EST)
  • References: <200803250614.BAA10496@smc.vnet.net>

On Mar 25, 2008, at 2:14 AM, 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
>

Here is an algo-rhythmic newbie approach :)

> In[2]:=
> Last[Reap[While[
>     Length[lst] >= 1,
>     i = Random[Integer,
>        {1, Length[lst]}];
>      c = lst[[i]];
>      rc = Reverse[c];
>      If[Length[Position[lst,
>           rc]] > 0 &&
>        c != rc,
>       Sow[{c, rc}]; , Null];
>      lst = Delete[lst,
>        Position[lst, rc]];
>      lst = Delete[lst,
>        Position[lst, c]]; ]]]
> Out[2]=
> {{{{4, 1}, {1, 4}},
>    {{3, 1}, {1, 3}}}}


J=E1nos



----------------------------------------------
Trying to argue with a politician is like lifting up the head of a 
corpse.
(S. Lem: His Master Voice)



  • Prev by Date: Re: Tally
  • Next by Date: Re: Basic plotting of an evaluated function
  • Previous by thread: Match Pairs of Numbers
  • Next by thread: Re: Match Pairs of Numbers