Re: Pattern Matching in Lists

*To*: mathgroup at smc.vnet.net*Subject*: [mg35570] Re: [mg35547] Pattern Matching in Lists*From*: "Julio Vera" <jvera at adinet.com.uy>*Date*: Fri, 19 Jul 2002 06:08:42 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

Anthony, Here´s how I´d do it. Load a package that contains the function Frequencies In[1]:= <<Statistics`DataManipulation` Then apply the function Frequencies to a Partition of w that contains pairs of it´s elements, each of them starting with each of the elements of w (except the last one, since it doesn´t have one to follow it). In[2]:= Frequencies[Partition[w,2,1]] Out[2]= {{3,{0,0}},{4,{0,1}},{4,{1,0}},{2,{1,1}}} The third element of this list shows w contains 4 elements 1 that are followed by an element 0 . Julio > > ----- Mensaje original ----- > De: "Anthony Mendes" <amendes at zeno.ucsd.edu> > Para: <mathgroup at smc.vnet.net> > Enviado: Jueves 18 de Julio de 2002 04:06 AM > Asunto: [mg35547] Pattern Matching in Lists > > > > Hello, > > > > Suppose w={1,1,1,0,0,1,0,1,0,0,1,0,0}. > > > > How can I count the number of occurrences of a 1 in w immediately > > followed by a 0 in w? > > > > I have tried every incarnation of Count[] I can think of; for example, > > > > Count[w,{___,1,0,___}] > > > > does not seem to work. In general, how can I count the number of > > occurrences of a 1 followed by a 0 in a list of 1's and 0's? Thank you! > > > > > > -- > > Tony > > _____________________ > > amendes at math.ucsd.edu > > > > >