Re: Pattern Matching in Lists
- To: mathgroup at smc.vnet.net
- Subject: [mg35558] Re: [mg35547] Pattern Matching in Lists
- From: Adriano Pascoletti <pascolet at dimi.uniud.it>
- Date: Fri, 19 Jul 2002 06:08:00 -0400 (EDT)
- References: <200207180706.DAA05322@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
At 3:06 -0400 18-07-2002, 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!
Anthony,
a possible solution is
In[16]:=
w={1,1,1,0,0,1,0,1,0,0,1,0,0};
Count[Partition[w,2,1],{1,0}]
Out[17]=
4
with matches at
In[18]:=
Position[Partition[w,2,1],{1,0}]
Out[18]=
{{3},{6},{8},{11}}
Adriano Pascoletti
- References:
- Pattern Matching in Lists
- From: Anthony Mendes <amendes@zeno.ucsd.edu>
- Pattern Matching in Lists