       Re: the faster way to find repeated sublists

• To: mathgroup at smc.vnet.net
• Subject: [mg60963] Re: [mg60923] the faster way to find repeated sublists
• From: János <janos.lobb at yale.edu>
• Date: Wed, 5 Oct 2005 02:28:06 -0400 (EDT)
• References: <200510040524.BAA17873@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```On Oct 4, 2005, at 1:24 AM, 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

Here is a newbie approach:

In:=
lst = Flatten[Table[{a, b},
{i, 1, 5}]]
Out=
{a, b, a, b, a, b, a, b, a, b}

In:=
sublst = {a, b}
Out=
{a, b}

In:=
f[l_List, s_List] :=
If[Length[l]/Length[s] ==
Length[Position[Partition[
l, Length[s], 1], s]],
True, False]

In:=
f[lst, sublst]
Out=
True

In:=
tst = lst
Out=
{a, b, a, b, a, b, a, b, a, b}

In:=
lst = Join[tst, {a}]
Out=
{a, b, a, b, a, b, a, b, a,
b, a}

In:=
f[lst, sublst]
Out=
False

János

----------------------------------------------
Trying to argue with a politician is like lifting up the head of a
corpse.
(S. Lem: His Master Voice)

```

• Prev by Date: Re: Partition(divid string to substring
• Next by Date: Re: the faster way to find repeated sublists
• Previous by thread: Re: the faster way to find repeated sublists
• Next by thread: Re: the faster way to find repeated sublists