Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: rule based program for "Deleting repeated members of a list."

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82073] Re: rule based program for "Deleting repeated members of a list."
  • From: Norbert Marxer <marxer at mec.li>
  • Date: Thu, 11 Oct 2007 00:21:29 -0400 (EDT)
  • References: <fe7j44$qga$1@smc.vnet.net><fea9ju$k4g$1@smc.vnet.net>

On 10 Okt., 10:31, Jean-Marc Gulliet <jeanmarc.gull... at gmail.com>
wrote:
> mumat wrote:
> > On Oct 6, 5:05 am, mumat <csar... at gmail.com> wrote:
> >> Hi,
>
> >> I have a list s={a,b,c,c,d,e,e,f,g,g,g,h,a,b};
>
> >> I need to write a program so that it reads the list and ignors
> >> repeated elements; so it outputs the following:
>
> >> RepeatRemover[s]={a,b,c,d,e,f,g,h,a,b};
>
> >> I am looking for a rule-based program to do this!
>
> >> Any help would be greatly appreciated.
>
> >> C.S.
>
> > Thanks so much.
>
> > Unrepeat[lis_List]:=lis//.{a___,b_,d_,e___}:>{a,b,e}/;b==d;
>
> I was wandering why you used b and d as pattern name with a condition on
> them rather than b and c, but I realized that when using c as pattern
> name in place of d the replacement fails.
>
> In[1]:= s = {a, b, c, c, d, e, e, f, g, g, g, h, a, b};
> s //. {a___, b_, c_, d___} :> {a, b, c} /; b == c
> s //. {a___, b_, d_, e___} :> {a, b, e} /; b == d
>
> Out[2]= {a, b, c, c}
>
> Out[3]= {a, b, c, d, e, f, g, h, a, b}
>
> Does anyone know why?
>
> Regards,
> --
> Jean-Marc- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Hello

Yes, I know why.

The second line in your code
     s //. {a___, b_, c_, d___} :> {a, b, c} /; b == c
is wrong.

The third argument in the list should be d (not c): e.g.
     s //. {a___, b_, c_, d___} :> {a, b, d} /; b == c


Best Regards
Norbert Marxer




  • Prev by Date: Re: "dereference" variable
  • Next by Date: Re: Re: rule based program for "Deleting repeated members of a list."
  • Previous by thread: Re: rule based program for "Deleting repeated members of a list."
  • Next by thread: Re: rule based program for "Deleting repeated members of a list."