MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: the faster way to find repeated sublists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60972] Re: the faster way to find repeated sublists
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Wed, 5 Oct 2005 02:28:28 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 10/4/05 at 1:24 AM, giampiero196019 at yahoo.it (giampiero) wrote:

>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.

The following works:

In[1]:=
f[x_List, y_List] := 
  Module[{p = Partition[x, Length[y]]}, 
   Flatten[Union[p]] == y && Length[Flatten[p]] ==  Length[x]]

In[2]:=
f[{1, 2, 1, 2, 1, 2}, {1, 2}]
Out[2]=
True

In[3]:=
f[{1, 2, 3, 1, 2, 3}, {1, 2, 3}]
Out[3]=
True

In[4]:=
f[{1, 2, 1, 2, 3}, {1, 2}]
Out[4]=
False
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Pure Function for String Selection
  • 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