Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Group and Replace itens sequence in a list
Replies: 10   Last Post: Aug 29, 2012 1:14 AM

 Messages: [ Previous | Next ]
 Ulrich Arndt Posts: 53 Registered: 10/1/09
Re: Group and Replace itens sequence in a list
Posted: Aug 23, 2012 8:56 PM

Map[Replace[#, {X, y___} -> {y}] &,
Split[ReplaceRepeated[
l, {x___, a, b, a, y___} -> {x, X, y}], #2 =!= X &]]

Map[DeleteCases[#, X] &,
Split[ReplaceRepeated[
l, {x___, a, b, a, y___} -> {x, X, y}], #2 =!= X &]]

Am 23.08.2012 um 08:52 schrieb Murta:

> Hi All
>
> I have a simple problem that is:
>
> l={1,2,3,a,b,a,4,5,6,a,b,c,7,8,9,a,b,a,10,11,12}
>
> I want to replace all a,b,a sequence by X to get:
>
> l={1,2,3,X,4,5,6,a,b,7,8,9,X,10,11,12}
>
> Then I want to group it by X intervals as
> l={{1,2,3},{4,5,6,a,b,7,8,9},{10,11,12}}
>
> If I don't need to put the intermediate X, even better!
> I think the with pattern, RaplaceAll and DeleteCases I can do It. Some clue?
> Tks
> Murta
>
>
>

Date Subject Author
8/23/12 Ulrich Arndt
8/23/12 Ulrich Arndt
8/24/12 Bob Hanlon
8/25/12 Murta
8/25/12 Simons, F.H.
8/26/12 Murta
8/28/12 Ulrich Arndt
8/29/12 Dana DeLouis