Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

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





  • Prev by Date: Re: Output of left-hand side of expression
  • Next by Date: Re: Equation to Postscript
  • Previous by thread: Re: Pattern Matching in Lists
  • Next by thread: RE: Pattern Matching in Lists