RE: Pattern Matching in Lists
- To: mathgroup at smc.vnet.net
- Subject: [mg35555] RE: [mg35547] Pattern Matching in Lists
- From: "Florian Jaccard" <jaccardf at eicn.ch>
- Date: Fri, 19 Jul 2002 06:07:55 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hello ! Here my first try. But there surely exist's a better method ! In[1]:= w={1,1,1,0,0,1,0,1,0,0,1,0,0}; In[2]:= f[0]=0; In[3]:= Table[If[w[[i]]==1 && w[[i+1]]==0,f[i]=f[i-1]+1,f[i]=f[i-1]],{i,1, Length[w]}]//Last Out[3]= 4 Meilleures salutations Florian Jaccard EICN-HES e-mail : jaccardf at eicn.ch -----Message d'origine----- De : Anthony Mendes [mailto:amendes at zeno.ucsd.edu] Envoyé : jeu., 18. juillet 2002 09:07 À : mathgroup at smc.vnet.net Objet : [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