MathGroup Archive 1999

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

Search the Archive

Re: Fast List-Selection

  • To: mathgroup at smc.vnet.net
  • Subject: [mg19908] Re: [mg19880] Fast List-Selection
  • From: "Arnold Knopfmacher" <arnoldk at cam.wits.ac.za>
  • Date: Tue, 21 Sep 1999 02:22:45 -0400
  • Organization: MS, University of the Witwatersrand
  • Sender: owner-wri-mathgroup at wolfram.com

Here is one approach to finding starting positions of n consecutive identical 
elements:

 nConsec[l_,n_]:=
  Flatten[Position[Partition[l,n,1],{x__} /;Length[Union[{x}]]==1]]

s={2,3,3,3,3,3,3,3,3,3,4,4,5,5,5,5,5,5,5,4}

nConsec[s,7]

{2,3,4,13}

Arnold Knopfmacher

> Date:          Sun, 19 Sep 1999 18:47:32 -0400
> From:          Hans Havermann <haver at total.net>
> To:            mathgroup at smc.vnet.net
> Subject: [mg19908]       [mg19880] Fast List-Selection

> I have a list 's' composed of a large number of (small) integers. I wish to
> search this list for instances of 7 consecutive, identical elements.
> 
> My approach is:
> 
> Do[If[Count[t = Take[s, {i, i + 6}], t[[1]]] == 7,
>     Print[i]], {i, 1, Length[s] - 6}]
> 
> Can anyone think of a *faster* way of doing this?
> 
> 
> 
> 


  • Prev by Date: Plotting Intervals on the numberline
  • Next by Date: Re: Fast List-Selection
  • Previous by thread: Re: Fast List-Selection
  • Next by thread: Re: Fast List-Selection