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: [mg35590] Re: Pattern Matching in Lists
  • From: "Carl K. Woll" <carlw at u.washington.edu>
  • Date: Sun, 21 Jul 2002 01:01:08 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Anthony and newsgroup,

I thought of another method of  solving this problem which is 5 or 6  times
faster than my previous version. Here is a test case.

tst=Table[Random[Integer],{1000000}];

My first solution was

In[16]:=
Count[Partition[tst,2,1],{1,0}]//Timing
Out[16]=
{0.704 Second, 249722}

My second solution is

In[17]:=
Tr[Drop[tst,-1](Drop[tst,-1]-Drop[tst,1])]//Timing
Out[17]=
{0.125 Second, 249722}

Carl Woll
Physics Dept
U of Washington

"Anthony Mendes" <amendes at zeno.ucsd.edu> wrote in message
news:ah5qce$59o$1 at smc.vnet.net...
>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: Q: Solving Numerical Matrix-Equation
  • Next by Date: Re: Pattern Matching in Lists
  • Previous by thread: RE: Pattern Matching in Lists
  • Next by thread: Re: Pattern Matching in Lists