Here's another approach for finding the first maximum
subsequence:
mss=: (#~ [: ((i. >./) ({ = ]) +/\@(0&=)) [: (- <./\) +/\)&.(_1&,)
mss 1 2 3 _50 4 5 6 _60 5 5 5 _50 3 5 7
4 5 6
The basic expression for finding local subsequence
maxima is
(- <./\) +/\ data
(I remember seeing this posted to these forums before, but
I do not remember who to give credit for it.)
The expression ((i. >./) ({ = ]) +/\@(0&=)) groups its
argument in sequences delimited by zeros, finds the
first instance of a global maximum and returns true
for items within the group containing that maximum
value.
And, #~ is being used in a hook, to pull out the
numbers from the original argument corresponding
to this group.
Finally, I am using this hook under (_1&,) which means
that each group is guaranteed to begin with a negative
number which will be discarded from the result.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm