Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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: [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[2]:=
lst = Flatten[Table[{a, b},
     {i, 1, 5}]]
Out[2]=
{a, b, a, b, a, b, a, b, a, b}

In[3]:=
sublst = {a, b}
Out[3]=
{a, b}

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

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

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

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

In[27]:=
f[lst, sublst]
Out[27]=
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