Re: finding the position of a pattern in list
- To: mathgroup at smc.vnet.net
- Subject: [mg64663] Re: finding the position of a pattern in list
- From: "Ray Koopman" <koopman at sfu.ca>
- Date: Sat, 25 Feb 2006 02:53:26 -0500 (EST)
- References: <dtm5mr$hfj$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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}