Skip et al.--
"Cut" may indeed come to mind for examining consecutive digits.  A more 
appropriate adverb, however, is "Infix":
--Compare each pair of adjacent digits for equality
--Examine each pair of adjacent comparisons (or longer groups for longer runs) 
for all 1's
--Extract from the list those items which produce any all-1's
   (([: ([: +./ 2 */\ 2 =/\ ])"1 ":@,.@]) # ]) 123334 122344 121212 111222 11212
123334 111222

Another srategy is to use "Insert" to accumulate consecutive matches.  Since 
the inserted verb operates on only the next leftward element and the prior 
accumulation, the returned value will show only the length of the leading 
string--unless the accumulation includes a list of the earlier counts.  The 
inserted verb, therefore, counts repeated 1's, but resets to 0 for inequality, 
while appending the previous counts to the result.  The positive items of the 
returned list may be examined for presence of a chosen value, the number of its 
occurrences (some implied in higher counts), or the maximal count.
   ((2 e.   [: (] ,~ [ * {.@] + [)/    0  ,    [: (}. = }:)   ":@   ])"0 # ])] 
123334 122344 121212 111222 112122
123334 111222
   ((2 e."1 [: (] ,~ [ * {.@] + [)/"1 (0) ,~"1 [: (}. = }:)"1 ":@,.@])   # ])] 
123334 122344 121212 111222 112122
123334 111222
   ((       [: (] ,~ [ * {.@] + [)/"1 (0) ,~"1 [: (}. = }:)"1 ":@,.@])      )] 
123334 122344 121212 111222 112122
0 0 2 1 0 0
0 1 0 0 1 0
0 0 0 0 0 0
2 1 0 2 1 0
1 0 0 0 1 0
The first version processes each number separately, the seond version saves a 
noticeable amount of time by performing the inserts in parallel.
--Art
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to