Re: the faster way to find repeated sublists
- To: mathgroup at smc.vnet.net
- Subject: [mg60958] Re: [mg60923] the faster way to find repeated sublists
- From: Pratik Desai <pdesai1 at umbc.edu>
- Date: Wed, 5 Oct 2005 02:27:57 -0400 (EDT)
- References: <200510040524.BAA17873@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
giampiero wrote:
>i'm newbie
>with a stupid problem
>
>a function for find repetead sublist in faster way
>
>ex
>f[{1,2,1,2,1,2},{1,2}]-> True cause {1,2} is repated three times
>f[{1,2,3,1,2,3},{1,2,3}]-> True cause {1,2,3} is repeated two times
>f[{1,2,1,2,3},{1,2}]->False cause after two {1,2} there is another
>symbol.
>
>True if the second list in containes many times exactly in first list
>False otherwise.
>
>
>bye everyone and sorry for my stupidity.
>
>giampiero
>
>
>
Hi
Here something I adapted from an example in help on Count for your problem
Clear[ww,pat]
ww = {1,2,1,2,1,2}
pat = {1, 2}
If[Count[NestList[Rest, ww,
Length[ww]], Append[pat, ___]] == Length[ww]/Length[pat], Print[
"True"], Print["False"]]
>>True
Clear[ww,pat]
ww = {1, 2, 3, 1, 2, 3}
pat = {1, 2, 3}
If[Count[NestList[Rest, ww, Length[ww]], Append[
pat, ___]] == Length[ww]/Length[pat], Print["True"], Print["False"]]
>>True
Clear[ww,pat]
ww = {1, 2, 1, 2, 3}
pat = {1, 2}
If[Count[NestList[Rest, ww,
Length[ww]], Append[pat, ___]] == Length[ww]/Length[pat], Print[
"True"], Print["False"]]
>>False
Hope this helps
Pratik .
--
Pratik Desai
Graduate Student
UMBC
Department of Mechanical Engineering
Phone: 410 455 8134
- References:
- the faster way to find repeated sublists
- From: "giampiero" <giampiero196019@yahoo.it>
- the faster way to find repeated sublists