Jump to content

Greatest subsequential sum: Difference between revisions

→‎{{header|RPL}}: HP-49 version
(add RPL)
(→‎{{header|RPL}}: HP-49 version)
Line 3,365:
size NOT '''THEN END''' <span style="color:grey">@ empty list case</span>
size 1 == '''THEN''' <span style="color:grey">@ singleton case</span>
'''IF''' ininput 1 GET 0 < '''THEN''' SWAP '''ELSE'''DROP input '''END'''
'''END'''
input 0 < ΠLIST NOT '''THEN''' <span style="color:grey">@ for any list with at least 1 item > 0</span>
Line 3,388:
1: { { } { 2 } { 2 -1 3 } { 1 2 } { 3 5 6 -2 -1 4 } }
</pre>
====Using matrices====
{{trans|Fortran}}
{{works with|HP|49}}
≪ DUP SIZE → input size
≪ { }
'''CASE'''
size 1 == '''THEN''' <span style="color:grey">@ singleton case</span>
'''IF''' input 1 GET 0 ≥ '''THEN''' DROP input '''END'''
'''END'''
size '''THEN'''
DROP
size DUP ≪ → j k ≪ '''IF''' j k ≤ '''THEN''' input j k SUB 0 + ∑LIST '''ELSE''' 0 '''END''' ≫ ≫ LCXM
<span style="color:grey">@ forall(i=1:an,j=1:an) mix(i,j) = sum(a(i:j))</span>
OBJ→ ΠLIST →LIST DUP ≪ MAX ≫ STREAM POS <span style="color:grey">@ m = maxloc(mix)</span>
1 - size IDIV2 R→C (1,1) + input SWAP C→R SUB <span style="color:grey">@ print *, a(m(1):m(2))</span>
'''END'''
'''END'''
≫ ≫ '<span style="color:blue">BIGSUB</span>' STO
 
=={{header|Ruby}}==
1,151

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.