In the paper "Combinatory Logic and Combinators in Array Languages" they give a solution in APL:
vec ← 1 1 0 1 1 1 0 0 0 1
⍝ split (partition) on zeroes
⊆⍨vec
┌───┬─────┬─┐
│1 1│1 1 1│1│
└───┴─────┴─┘
⍝ size of each sublist
≢ ̈⊆⍨vec
2 3 1
⍝ max reduction
⌈/≢¨⊆⍨vec
3
For clarity, they also note:
The final maximum consecutive ones APL solution can be translated for those who don’t read APL:
reduce(max, map(length, W(partition, vec)))
So, how would one express the following in J?
⌈/≢¨⊆⍨vec
The ⊆
symbol seems to be a "partition" operator. It's not clear this exists in J but I may have just missed it. Curious what the above expression would be in "J".
;.
; for example,>./ #;._1 ]0, 1 1 0 1 1 1 0 0 0 1 NB. Returns 3
. I’ll try to find the time for a formal answer later. If I can’t or don’t, anyone at all is free to use this comment as a basis of their answer. No need for attribution. – Isotron(⌈/¯1-2-/∘⍸1,1,⍨~)
is a much more efficient function for computing this. – Evenings