MathGroup Archive 2006

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

Search the Archive

Re: finding the position of a pattern in list


Bob Hanlon wrote:
> Here is a faster method than the one that I first suggested.
>
> pos1[data_]:=Position[Partition[data,2,1],{0,1}]//Flatten;
>
> pos2[data_]:=Position[RotateLeft[data]-data,1]//Flatten;
>
> data=Table[Random[Integer],{100000}];
>
> pos1[data]==pos2[data]
>
> True

Whenever data has a leading 1 and a trailing 0, pos2 will include
the index of the last position, which pos1 will never do.

pos1[{1,0}]
pos2[{1,0}]
{}
{2}


  • Prev by Date: Re: Plot -> axes inversion
  • Next by Date: autogenerated packages carriage returns and line feeds
  • Previous by thread: Re: finding the position of a pattern in list
  • Next by thread: Re: finding the position of a pattern in list