On Thursday 23 February 2006 06:34, Gang Ma wrote:
> Hi,
> I am working on a program to do the following: My data is a list of 0
> and 1. For example, {0,0,1,1,1,0,0,1,1,1,0}. I want to find the
> positions of all the pattern of {0,1}. In my previous example, the
> first {0,1} is at 2 and and the second {0,1} appears at 7. I can
> write a loop to do this, but I have several thousands such lists,
> the computation will be time consuming using loop.
Try this :
your data :
myList = {0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0}
myPattern = List[0, 1]
this generates all pairs built with consecutive elements :
Partition[myList, 2, 1]
this gives the expected result :
Position[Partition[myList, 2, 1], myPattern]