MathGroup Archive 1999

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

Search the Archive

Re: Fast List-Selection


Hi Hans,

Here is one idea:

rep[ls_]:=Position[Partition[ls,7,1],{x_ ..}]

For a 10000 element random list of integers (0,1,2), it took less than a
second. It'll be interesting to see the other solutions.

Carl Woll
Physics Dept
U of Washington

Hans Havermann wrote:

> 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: How can I get Divisors[n] from FactorInteger[n]?
  • Next by Date: Re: Limits of multi-var. functions
  • Previous by thread: Fast List-Selection
  • Next by thread: Re: Fast List-Selection