Re: Re: rule based program for "Deleting repeated members of a list."
- To: mathgroup at smc.vnet.net
- Subject: [mg82075] Re: [mg82034] Re: rule based program for "Deleting repeated members of a list."
- From: János <janos.lobb at yale.edu>
- Date: Thu, 11 Oct 2007 00:22:30 -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>
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
- References:
- Re: rule based program for "Deleting repeated members of a list."
- From: Jean-Marc Gulliet <jeanmarc.gulliet@gmail.com>
- Re: rule based program for "Deleting repeated members of a list."