Re: Re: Counting Runs
- To: mathgroup at smc.vnet.net
- Subject: [mg51924] Re: Re: [mg51890] Counting Runs
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Fri, 5 Nov 2004 02:17:18 -0500 (EST)
- Reply-to: hanlonr at cox.net
- Sender: owner-wri-mathgroup at wolfram.com
One more example Length/@Split@Sort[First/@Split[v]] Bob Hanlon > > From: Bob Hanlon <hanlonr at cox.net> To: mathgroup at smc.vnet.net > Date: 2004/11/04 Thu AM 06:21:27 EST > To: Gregory Lypny <gregory.lypny at videotron.ca>, <mathgroup at smc.vnet.net> > Subject: [mg51924] Re: [mg51890] Counting Runs > > v={1,1,1,-1,1,1,1,1,1,-1,-1,-1,-1,1}; > > Length/@Split@Sort@Cases[Split[v], x_List:>x[[1]]] > > {2,3} > > Length/@Split@Sort[v//.{s___,x_,x_,e___}:>{s,x,e}] > > {2,3} > > > Bob Hanlon > > > > > From: Gregory Lypny <gregory.lypny at videotron.ca> To: mathgroup at smc.vnet.net > > Date: 2004/11/04 Thu AM 01:50:22 EST > > To: mathgroup at smc.vnet.net > > Subject: [mg51924] [mg51890] Counting Runs > > > > Looking for an elegant way to count runs to numbers in a series. > > Suppose I have a list of ones and negative ones such as > > v={1,1,1,-1,1,1,1,1,1,-1,-1,-1,-1,1}. > > I'd like to create a function that counts the number of runs of 1s and > > -1s, which in this case is 3 and 2. > > > > Greg > > > > > Bob Hanlon Chantilly, VA