Greatest subsequential sum: Difference between revisions
m
→{{header|Perl 6}}: Modernize; no longer need to work around bug
(added kotlin) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Modernize; no longer need to work around bug) |
||
Line 2,101:
{{trans|Python}}
{{works with|Rakudo|
<lang perl6>sub
my ($start, $end, $sum, $maxsum) = -1, -1, 0, 0;
for @a.kv -> $i, $x {
Line 2,120:
For each starting position, we calculate all the subsets starting at that position.
They are combined with the best subset ($
The best of those @subsets is saved at the new $
Consuming the array (.shift) allows us to skip tracking the starting point; it is always 0.
The empty sequence is used to initialize $
▲<lang perl6>sub max_sub-seq ( *@a ) {
my $
while @a {
my @subsets =
@subsets.push
$
@a.shift;
}
return $
}
{{out}}
<pre>
=={{header|Phix}}==
|