26 lines
641 B
Text
26 lines
641 B
Text
module Greatest_subsequential_sum {
|
|
showGSS=lambda (a)->{
|
|
function Greatest_subsequential_sum(a as array){
|
|
s=a#sum()
|
|
=a
|
|
p=len(a)-1
|
|
if p<0 then exit
|
|
for i=0 to p
|
|
for j=i to p
|
|
k= a#slice(i, j)
|
|
m=k#sum()
|
|
if m>s then =k: s=m
|
|
next
|
|
next
|
|
}
|
|
= "("+a#str$(",")+") -> ("+ Greatest_subsequential_sum(a)#str$(",")+")"
|
|
}
|
|
open "out.txt" for output as#f
|
|
print #f, showGSS((-1 , 2 , -1))
|
|
print #f, showGSS((-1, 2, -1, 3, -1))
|
|
print #f, showGSS((-1, 1, 2, -5, -6))
|
|
print #f, showGSS((-1 , -2 , 3 , 5 , 6 , -2 , -1 , 4 , -4 , 2 , -1))
|
|
close #f
|
|
win notepad, dir$+"out.txt"
|
|
}
|
|
Greatest_subsequential_sum
|