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

MathGroup Archive 2007

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82112] Re: [mg82075] Re: [mg82034] Re: rule based program for "Deleting repeated members of a list."
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Fri, 12 Oct 2007 02:59:40 -0400 (EDT)
  • References: <fe7j44$qga$1@smc.vnet.net> <3917603.1191869840479.JavaMail.root@m35> <fefi83$jfi$1@smc.vnet.net> <200710100823.EAA26517@smc.vnet.net> <29927840.1192136597320.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

> As a latecomer newbie, I would forget about rules here.
>
> In[3]:=
> First /@ Split[s]
> Out[3]=
> {a, b, c, d, e, f, g, h, a, b}

And, as I've said before, Split[s][[All,1]] is even faster.

Bobby

On Wed, 10 Oct 2007 23:22:30 -0500, János <janos.lobb at yale.edu> wrote:

>
> On Oct 10, 2007, at 4:23 AM, Jean-Marc Gulliet wrote:
>
>> DrMajorBob wrote:
>>
>>> Union with one argument is the same thing as Union, and it sorts;
>>> the OP
>>> didn't want it sorted.
>>>
>>> Bobby
>>>
>>> On Mon, 08 Oct 2007 01:07:55 -0500, sean_incali
>>> <sean_incali at yahoo.com>
>>> wrote:
>>>
>>>> How about a simplests way of using intersection, instead of rule
>>>> based.
>>>>
>>>> s = {a, b, c, c, d, e, e, f, g, g, g, h, a, b} // Intersection
>>>> {a, b, c, d, e, f, g, h}
>>>>
>>>>
>>>>
>>>>
>>>> On Oct 6, 2: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};
>> ----------------------^^^-------------^^^
>> Note that not only the desired output is not sorted but also non
>> consecutive possibly repeated elements must not be discarded.
>>
>>>>>
>>>>> I am looking for a rule-based program to do this!
>>>>>
>>>>> Any help would be greatly appreciated.
>>
>> To get the desired output, one must *map* Union, Intersection, or
>> Complement onto the split list according to the running elements.
>>
>> In[1]:= s = {a, b, c, c, d, e, e, f, g, g, g, h, a, b};
>> Union /@ Split@s // Flatten
>> Intersection /@ Split@s // Flatten
>> Complement /@ Split@s // Flatten
>> s //. {a___, b_, b_, c___} -> {a, b, c}
>> s //. {a___, b_, d_, e___} :> {a, b, e} /; b == d
>>
>> Out[2]= {a, b, c, d, e, f, g, h, a, b}
>>
>> Out[3]= {a, b, c, d, e, f, g, h, a, b}
>>
>> Out[4]= {a, b, c, d, e, f, g, h, a, b}
>>
>> Out[5]= {a, b, c, d, e, f, g, h, a, b}
>>
>> Out[6]= {a, b, c, d, e, f, g, h, a, b}
>>
>> Regards,
>> --
>> Jean-Marc
>
> As a latecomer newbie, I would forget about rules here.
>
> In[3]:=
> First /@ Split[s]
> Out[3]=
> {a, b, c, d, e, f, g, h, a, b}
>
> J=E1nos
>
>
> ------------------------------------------
> "The shortest route between two points is the middleman"  Ayn Rand
>
>
>



-- 
DrMajorBob at bigfoot.com


  • Prev by Date: Re: Re: problem with contourplot
  • Next by Date: Re: JLink
  • Previous by thread: Re: 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."