MathGroup Archive 2002

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

Search the Archive

RE: Pattern Matching in Lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35583] RE: [mg35547] Pattern Matching in Lists
  • From: "Florian Jaccard" <jaccardf at eicn.ch>
  • Date: Fri, 19 Jul 2002 06:09:59 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hello Anthony !

Here a much better method then the one I posted yesterday.
It has been found by Jean Beiner :

In[44]:=
count10[list_]:=Count[Partition[list,2,1],{1,0}]

In[49]:=
example=Table[Random[Integer,{0,1}],{25}]

Out[49]=
{1,1,1,0,1,1,0,1,1,1,0,1,0,0,1,0,0,0,0,0,1,0,0,1,1}

In[50]:=
count10[example]

Out[50]=
6

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: Equation to Postscript
  • Next by Date: RE: Pattern Matching in Lists
  • Previous by thread: RE: Pattern Matching in Lists
  • Next by thread: RE: Pattern Matching in Lists