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: [mg35569] RE: [mg35547] Pattern Matching in Lists
  • From: "DrBob" <majort at cox-internet.com>
  • Date: Fri, 19 Jul 2002 06:08:38 -0400 (EDT)
  • Reply-to: <drbob at bigfoot.com>
  • Sender: owner-wri-mathgroup at wolfram.com

How's this?

w = {1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0};
Count[Transpose[{Drop[w, -1], Drop[w, 1]}], {1, 0}]

4

If you want the list treated as a cycle, so that 1 at the end and 0 at
the beginning counts as a match, here's a different example input and
different counting method:

w2 = {0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1};
Count[Transpose[{w2, RotateRight[w2, 1]}], {1, 0}]

5

Bobby Treat

-----Original Message-----
From: Anthony Mendes [mailto:amendes at zeno.ucsd.edu] 
To: mathgroup at smc.vnet.net
Subject: [mg35569] [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: Pattern Matching in Lists
  • Next by Date: Re: Pattern Matching in Lists
  • Previous by thread: RE: Pattern Matching in Lists
  • Next by thread: Re: Pattern Matching in Lists