Re: Counting Runs
- To: mathgroup at smc.vnet.net
- Subject: [mg51919] Re: Counting Runs
- From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
- Date: Fri, 5 Nov 2004 02:17:12 -0500 (EST)
- Organization: Uni Leipzig
- References: <cmclmu$i99$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
v={1,1,1,-1,1,1,1,1,1,-1,-1,-1,-1,1}
Length /@ Split[Sort[First /@ Split[v]]]
gives you {2,3}
Regards
Jens
"Gregory Lypny" <gregory.lypny at videotron.ca> schrieb im Newsbeitrag
news:cmclmu$i99$1 at smc.vnet.net...
> 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
>