+./@E. is backed by special code. Thus: ts=: 6!:2 , 7!:2@]
b=: 0<1e6 ?@$ 4 ts '(42$1) +./@E. b' 0.000961575 1600 ts '42 (1 e. ([#1:) E. ]) b' 0.00308224 1.05018e6 Another phrase finds the maximum number of consecutive 1s: cut where b has a 1 preceded by a 0, and sum the cut. >./ (b>}:0,b) +/;.1 b 42 ts '>./ (b>}:0,b) +/;.1 b' 0.0198919 4.19635e6 ----- Original Message ----- From: Thomas Costigliola <[email protected]> Date: Thursday, October 13, 2011 15:18 Subject: Re: [Jprogramming] Operations on boolean lists To: Programming forum <[email protected]> > N (1 e.([#1:)E.]) 1 0 ... > > On Oct 13, 2011 5:58 PM, "David Vaughan" > <[email protected]>wrote: > > > > How could I test if a boolean list contains at least n > consecutive 1's? > > > > e.g. for 3 consecutive 1's: > > > > desiredverb 0 1 1 1 0 0 > > 1 > > desiredverb 0 1 1 0 1 1 > > 0 > > desiredverb 1 1 1 1 1 0 > > 1 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
