Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #11482 > unrolled thread

Re: Group and Replace itens sequence in a list

Started byBob Hanlon <hanlonr357@gmail.com>
First post2012-08-24 09:07 +0000
Last post2012-08-25 08:34 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Group and Replace itens sequence in a list Bob Hanlon <hanlonr357@gmail.com> - 2012-08-24 09:07 +0000
    Re: Group and Replace itens sequence in a list Murta <rodrigomurtax@gmail.com> - 2012-08-25 08:34 +0000

#11482 — Re: Group and Replace itens sequence in a list

FromBob Hanlon <hanlonr357@gmail.com>
Date2012-08-24 09:07 +0000
SubjectRe: Group and Replace itens sequence in a list
Message-ID<k17g8b$dr7$1@smc.vnet.net>
Clear[f]

f[list_?VectorQ] := Cases[
  (list //. {s___, a, b, a, r___} -> {{s}, {r}}) /.
   {} ->
    Sequence[], _?VectorQ, Infinity]

f[{1, 2, 3, a, b, a, 4, 5, 6, a, b, c, 7, 8, 9, a, b, a, 10, 11, 12}]

{{1, 2, 3}, {4, 5, 6, a, b, c, 7, 8, 9}, {10, 11, 12}}

f[{a, b, a, 1, 2, 3, a, b, a, 4, 5, 6, a, b, c, 7, 8, 9, a, b, a, 10,
  11, 12}]

{{1, 2, 3}, {4, 5, 6, a, b, c, 7, 8, 9}, {10, 11, 12}}

f[{1, 2, 3, a, b, a, 4, 5, 6, a, b, c, 7, 8, 9, a, b, a, 10, 11, 12,
  a, b, a}]

{{1, 2, 3}, {4, 5, 6, a, b, c, 7, 8, 9}, {10, 11, 12}}

f[{a, b, a, 1, 2, 3, a, b, a, 4, 5, 6, a, b, c, 7, 8, 9, a, b, a, 10,
  11, 12, a, b, a}]

{{1, 2, 3}, {4, 5, 6, a, b, c, 7, 8, 9}, {10, 11, 12}}


Bob Hanlon


On Thu, Aug 23, 2012 at 2:52 AM, Murta <rodrigomurtax@gmail.com> wrote:
> 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
>
>
>

[toc] | [next] | [standalone]


#11495

FromMurta <rodrigomurtax@gmail.com>
Date2012-08-25 08:34 +0000
Message-ID<k1a2m8$iga$1@smc.vnet.net>
In reply to#11482
Tks for Bob and Ulrich!
I choosed to work with this combination of both

SplitAt[list_,spliter_]:=Module[{l},
	l=(list//.{s___,Sequence@@spliter,r___}->{{s},{r}})/.{}->Sequence[];
	Cases[l,_?VectorQ,Infinity]
]

On Friday, August 24, 2012 6:07:23 AM UTC-3, Bob Hanlon wrote:
> Clear[f]
> 
> 
> 
> f[list_?VectorQ] := Cases[
> 
>   (list //. {s___, a, b, a, r___} -> {{s}, {r}}) /.
> 
>    {} ->
> 
>     Sequence[], _?VectorQ, Infinity]
> 
> 
> 
> f[{1, 2, 3, a, b, a, 4, 5, 6, a, b, c, 7, 8, 9, a, b, a, 10, 11, 12}]
> 
> 
> 
> {{1, 2, 3}, {4, 5, 6, a, b, c, 7, 8, 9}, {10, 11, 12}}
> 
> 
> 
> f[{a, b, a, 1, 2, 3, a, b, a, 4, 5, 6, a, b, c, 7, 8, 9, a, b, a, 10,
> 
>   11, 12}]
> 
> 
> 
> {{1, 2, 3}, {4, 5, 6, a, b, c, 7, 8, 9}, {10, 11, 12}}
> 
> 
> 
> f[{1, 2, 3, a, b, a, 4, 5, 6, a, b, c, 7, 8, 9, a, b, a, 10, 11, 12,
> 
>   a, b, a}]
> 
> 
> 
> {{1, 2, 3}, {4, 5, 6, a, b, c, 7, 8, 9}, {10, 11, 12}}
> 
> 
> 
> f[{a, b, a, 1, 2, 3, a, b, a, 4, 5, 6, a, b, c, 7, 8, 9, a, b, a, 10,
> 
>   11, 12, a, b, a}]
> 
> 
> 
> {{1, 2, 3}, {4, 5, 6, a, b, c, 7, 8, 9}, {10, 11, 12}}
> 
> 
> 
> 
> 
> Bob Hanlon
> 
> 
> 
> 
> 
> On Thu, Aug 23, 2012 at 2:52 AM, Murta <rodrigomurtax@gmail.com> wrote:
> 
> > 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
> 
> >
> 
> >
> 
> >

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web