Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Or in a Select question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67109] Re: Or in a Select question
  • From: "Ray Koopman" <koopman at sfu.ca>
  • Date: Fri, 9 Jun 2006 01:09:21 -0400 (EDT)
  • References: <e68q6i$d0p$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

János wrote:
> Hi,
>
> I have a list
>
> lst={a,b,c}
>
> I make another list from it the following way:
>
> In[2]:=
> pp = Partition[Tuples[lst, 2], 2, 1]
> Out[2]=
> {{{a, a}, {a, b}},
>    {{a, b}, {a, c}},
>    {{a, c}, {b, a}},
>    {{b, a}, {b, b}},
>    {{b, b}, {b, c}},
>    {{b, c}, {c, a}},
>    {{c, a}, {c, b}},
>    {{c, b}, {c, c}}}
>
>  From here I would like to select all the elements whose sublists
> contain only different elements.  So my "logical" selection was:
>
> In[54]:=
> Select[pp, #1[[1,1]] =!= #1[[1,2]] || #1[[2,1]] =!= #1[[2,2]] & ]
> Out[54]=
> {{{a, a}, {a, b}},
>    {{a, b}, {a, c}},
>    {{a, c}, {b, a}},
>    {{b, a}, {b, b}},
>    {{b, b}, {b, c}},
>    {{b, c}, {c, a}},
>    {{c, a}, {c, b}},
>    {{c, b}, {c, c}}}
>
> Well, that did not do any damage to the list.
> After some time I came up with this one:
>
> In[49]:=
> Complement[pp, Select[pp,
    Xor[#1[[1,1]] =!= #1[[1,2]],
        #1[[2,1]] =!= #1[[2,2]]] & ]]
> Out[49]=
> {{{a, b}, {a, c}},
>    {{a, c}, {b, a}},
>    {{b, c}, {c, a}},
>    {{c, a}, {c, b}}}
>
> That looks OK, but also looks too complicated.
> Why my "logical" one does not work here?

Are you sure you don't want AND instead of OR ?

In[4]:= Select[pp, UnsameQ@@#[[1]] && UnsameQ@@#[[2]] & ]
Out[4]= {{{a,b},{a,c}},
         {{a,c},{b,a}},
         {{b,c},{c,a}},
         {{c,a},{c,b}}}


  • Prev by Date: Re: Plotting Cosh(x)?
  • Next by Date: Re: Plot Sequencies of Complex Functions
  • Previous by thread: Re: Or in a Select question
  • Next by thread: Re: Or in a Select question