Re: Pattern Matching in Lists

• To: mathgroup at smc.vnet.net
• Subject: [mg35565] Re: Pattern Matching in Lists
• From: Selwyn Hollis <slhollis at earthlink.net>
• Date: Fri, 19 Jul 2002 06:08:26 -0400 (EDT)
• References: <ah5qce\$59o\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Here's a simple solution. Say you have a list of 0s and 1s named bits.
Compute bits + 2*RotateRight[bits] and drop the first entry. Then count
the number of 2s in the result.

counter10[bits_]:= Count[Drop[bits+2RotateRight[bits],1],2]

--
Selwyn Hollis
http://www.math.armstrong.edu/faculty/hollis

Anthony Mendes wrote:
> 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!
>
>

```

• Prev by Date: RE: Pattern Matching in Lists
• Next by Date: Comparison of Mathematica on Various Computers
• Previous by thread: RE: Pattern Matching in Lists
• Next by thread: RE: Pattern Matching in Lists