MathGroup Archive 2008

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

Search the Archive

Re: Tally

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86923] Re: Tally
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Wed, 26 Mar 2008 04:54:21 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fsa5eq$adg$1@smc.vnet.net>

Armen Kocharyan wrote:

> I'm trying the following:
> 
> 
> *Dlist = {{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}},{{0,1},{1,0}}};*
> 
> *Tally[Dlist,(#1=== #2) \[Or] *
> 
> *            (#1[[1]][[1]]=== #2[[1]][[2]] \[And] *
> 
> *             #1[[1]][[2]]=== #2[[1]][[1]] \[And] *
> 
> *             #1[[2]][[1]]=== #2[[2]][[2]] \[And] *
> 
> *             #1[[2]][[2]]=== #2[[2]][[1]] )&]*
> 
> 
> 
> The output is:
> 
> *{{{{0,1},{0,1}},1},{{{1,0},{1,0}},1},{{{1,0},{0,1}},2}}*
> 
> instead of
> 
> *{{{{0,1},{0,1}},2},{{{1,0},{0,1}},2}}*
> 
> 
> 
> If I remove the last member from DList
> 
> *Dlist = {{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}}};*
> 
> then I got a correct answer
> 
> *{{{{0,1},{0,1}},2},{{{1,0},{0,1}},1}}.*
> 
> 
> 
> Is anything wrong with my original code?


Although this does not answer your question, writing your expression as 
follows should help investigating its behavior (assuming, of course, I 
have correctly understood what you try to achieve).

Dlist={{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}},{{0,1},{1,0}}};

Tally[Dlist,
     ((#1 === #2) ||
      (#1[[1]] === Reverse@#2[[1]] &&
       #1[[2]] === Reverse@#2[[2]]) &)]

==> {{{{0,1},{0,1}},1},{{{1,0},{1,0}},1},{{{1,0},{0,1}},2}}


Best regards,
-- 
Jean-Marc


  • Prev by Date: Re: Tagged list processing
  • Next by Date: Re: Match Pairs of Numbers
  • Previous by thread: Re: Tally
  • Next by thread: Re: Tally