Dear Tracy et al
Please note that my mrs verb fails in some circumstances, and it is
advisable to prefix with a zero at some stage. This was pointed out
by Arie Groeneveld on 3 July 07, and discussed by me on the same
day. I suggested
mrs =: >./@(- <./\)@(0 , +/\) NB. proposed new verb
to get round the problem without too much loss in performance.
You actually want to recover the subsequence, and Raul's mss looks
good, though surprisingly seems to go astray on this example, which
I'll point out without trying to find out why as my wife wants me to help
with tidying up now the children have gone -
y NB. 20 random ints
0 _3 8 _1 _8 2 5 _5 5 3 8 0 _10 _5 _1 _4 4 _10 _4 _6
maxss y
2 5 _5 5 3 8
+/maxss y
18
mrs y
18
mss y
2 5 _5 5 3 8 0 _10 _5 _1
+/mss y
2
NB. FWIW - should be simpler and lose the leading zero ....
(+/\^:_1 @(}.~(0 i:~ ])) @ {.~(>:@i.>./))@(- <./\)@(0 , +/\) y
0 2 5 _5 5 3 8
I hope that helps
Mike
Tracy Harms wrote:
Thank you both, R. Miller and R.E. Boss, for bringing
to my attention the algorithm by Stephen Ostermiller
and its J code implementation by Mike Day. The
complete definition of mss is particularly useful,
Raul.
I remember noticing Mike Day's message when it
occurred in April, but I did not realize, when I took
on the Rosetta Code task, that it was the same basic
problem he has solved. Reading through the alternate
solution-approach is more interesting now that I've
applied myself to the problem, especially since it
gives an efficiency gain.
TBH
--
Tracy B. Harms
The advantages of executability and universality
found in programming languages can be effectively
combined, in a single coherent language, with the
advantages offered by mathematical notation.
Kenneth E. Iverson
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm