Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Counting Runs

  • To: mathgroup at
  • Subject: [mg51923] Re: [mg51890] Counting Runs
  • From: Bob Hanlon <hanlonr at>
  • Date: Fri, 5 Nov 2004 02:17:17 -0500 (EST)
  • Reply-to: hanlonr at
  • Sender: owner-wri-mathgroup at


Length/@Split@Sort@Cases[Split[v], x_List:>x[[1]]]




Bob Hanlon

> From: Gregory Lypny <gregory.lypny at>
To: mathgroup at
> Date: 2004/11/04 Thu AM 01:50:22 EST
> To: mathgroup at
> Subject: [mg51923] [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

  • Prev by Date: Re: foreach loop
  • Next by Date: Re: Counting Runs
  • Previous by thread: Re: Counting Runs
  • Next by thread: Re: Counting Runs