Jump to content

Greatest subsequential sum: Difference between revisions

→‎{{header|Quackery}}: improved efficiency
(Added Quackery.)
(→‎{{header|Quackery}}: improved efficiency)
Line 3,098:
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ stack ] is maxseq ( --> s )
[ stack ] is maxsum ( --> s )
 
[ 0 swap witheach + ] is sum ( --> s )
 
[ [] maxseq put
0 maxsum put
dup dup size times
[ dup[] size0 timesrot
[ dup i^ 1+ splitwitheach
drop dup sum[ rot over join
dup maxsum share > iffunrot +
[ dup maxsum replaceshare >
maxseq replace ]if
else 2drop ] [ dup maxsum replace
over maxseq replace ] ]
behead drop ]
2drop behead drop dup ]
maxsum2drop take
maxsum take
maxseq take ] is maxsubseqsum ( [ --> n [ )
[ 0 swapmaxseq witheach +take ] is sum ( is maxsubseqsum ( [ --> s n [ )
 
 
' [ [ 1 2 3 4 5 -8 -9 -20 40 25 -5 ]
[ -1 -2 3 5 6 -2 -1 4 -4 2 -1 ]
[ -1 -2 -3 -4 -5 ]
[ ] ]
witheach
[ dup
1,493

edits

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