RE: Re: Pattern Matching in Lists
- To: mathgroup at smc.vnet.net
- Subject: [mg35856] RE: [mg35854] Re: Pattern Matching in Lists
- From: "DrBob" <majort at cox-internet.com>
- Date: Sun, 4 Aug 2002 06:00:07 -0400 (EDT)
- Reply-to: <drbob at bigfoot.com>
- Sender: owner-wri-mathgroup at wolfram.com
Hagihara, Well... that method is more than ten times slower than any other method suggested, almost 300 times slower than the fastest. Here are timings (in seconds) for 13 methods on a list of 2 million entries. Your method is last in the list: {1.297, 0.578, 0.547, 0.203, 0.047, 0.125, 0.11, 0.546, 0.516, 0.672, 0.078, 0.047, 13.906} Bobby -----Original Message----- From: Daitaro Hagihara [mailto:daiyanh at earthlink.net] To: mathgroup at smc.vnet.net Subject: [mg35856] [mg35854] Re: Pattern Matching in Lists It seemed strange that no one mentioned pattern matching construct of _?. Count[{1,1,1,0,0,1,0,1,0,0,1,0,0}, _?((t=#==0&&i==1;i=#;t)&)] ==> 4 If different tests are needed on the same data set, it'd be advised to make test functions such as f[x_]:=(t=x==0&&i==1;i=x;t) and run Count[w,_?f]. The reason why {___,1,0,___} doesn't work is because patterns are matched elementwise. DH