MathGroup Archive 2002

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

Search the Archive

Re: Pattern Matching in Lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35596] Re: Pattern Matching in Lists
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Mon, 22 Jul 2002 02:10:51 -0400 (EDT)
  • References: <ahdfd2$i3i$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Carl,
Pushing your idea a bit further and avoiding one Drop and a subtraction of
lists:

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

    Tr[Drop[w,-1](Drop[w,-1]-Drop[w,1])]//Timing

        {7.85 Second,249850}

    (Tr[#]-Tr[# Drop[w,1]])&[Drop[w,-1] ]//Timing

        {2.75 Second,249850}

--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


"Carl K. Woll" <carlw at u.washington.edu> wrote in message
news:ahdfd2$i3i$1 at smc.vnet.net...
> 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: Re: How do I put Arrow Heads on the ends of the Axis of my plots?
  • Next by Date: RE: Re: Pattern Matching in Lists
  • Previous by thread: Re: Pattern Matching in Lists
  • Next by thread: RE: Re: Pattern Matching in Lists