A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
|
|
@ -0,0 +1,9 @@
|
|||
USING: kernel locals math math.order sequences ;
|
||||
|
||||
:: max-with-index ( elt0 ind0 elt1 ind1 -- elt ind )
|
||||
elt0 elt1 < [ elt1 ind1 ] [ elt0 ind0 ] if ;
|
||||
: last-of-max ( accseq -- ind ) -1 swap -1 [ max-with-index ] reduce-index nip ;
|
||||
|
||||
: max-subseq ( seq -- subseq )
|
||||
dup 0 [ + 0 max ] accumulate swap suffix last-of-max head
|
||||
dup 0 [ + ] accumulate swap suffix [ neg ] map last-of-max tail ;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
( scratchpad ) { -1 -2 3 5 6 -2 -1 4 -4 2 -1 } max-subseq dup sum swap . .
|
||||
{ 3 5 6 -2 -1 4 }
|
||||
15
|
||||
Loading…
Add table
Add a link
Reference in a new issue