Greatest subsequential sum: Difference between revisions

→‎{{header|RPL}}: Efficient solution
(→‎{{header|RPL}}: HP-49 version)
(→‎{{header|RPL}}: Efficient solution)
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}}
Line 3,405:
'''END'''
'''END'''
≫ ≫ '<span style="color:blue">BIGSUB</span>' STO
===Efficient solution===
Uses only basic RPL instructions for maximum compatibility.
{{trans|Euphoria}}
≪ DUP SIZE → s length
≪ <span style="color:red">{ }</span>
'''IF''' length '''THEN'''
<span style="color:red">0 (1 0)</span>
<span style="color:red">1</span> length '''FOR''' j
<span style="color:red">0</span>
j length '''FOR''' k
s k GET +
'''IF''' <span style="color:red">3</span> PICK OVER < '''THEN'''
ROT ROT DROP2
j k R→C OVER
'''END'''
'''NEXT''' DROP
'''NEXT''' SWAP DROP
'''IF''' DUP IM '''THEN''' s SWAP C→R SUB + '''ELSE''' DROP '''END'''
'''END'''
≫ ≫ '<span style="color:blue">BIGSUB</span>' STO
 
1,151

edits