[Jprogramming] maximum sub-sequence
R.E. Boss
r.e.boss at planet.nl
Thu Dec 27 06:14:43 HKT 2007
> (I remember seeing this posted to these forums before, but
> I do not remember who to give credit for it.)
http://www.jsoftware.com/pipermail/programming/2007-April/006160.html
R.E. Boss
> -----Oorspronkelijk bericht-----
> Van: programming-bounces at jsoftware.com [mailto:programming-
> bounces at jsoftware.com] Namens Raul Miller
> Verzonden: woensdag 26 december 2007 22:20
> Aan: Programming forum
> Onderwerp: Re: [Jprogramming] maximum sub-sequence
>
> 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
More information about the Programming
mailing list