Re: [Jprogramming] Maximum Subarray Problem

2019-02-24 Thread [email protected]
Hi, The version I know from https://github.com/kevinlawler/kona/wiki/Idioms is mss=: [: >./ (0 >. +)/\. It fails on lists of length 0 or 1 but is very concise; the following works on all list lengths but has a few extra characters: mss1=: [: >./ [: (0 >. +)/\. ,&0 which is an almost literal t

Re: [Jprogramming] Maximum Subarray Problem

2019-02-24 Thread 'Mike Day' via Programming
Trying your patience - better to use \. instead of ONE of the \ as in mxsasumcrude =: >./@:(>./@:( +/\. ) \ ) NB. less space or mxsasumcrude =: >./@:(>./@:( +/\ ) \. ) NB. more space The version using only " \ " goes wrong with lots of negative values. Better stop now! Mike On 24/02/2019

Re: [Jprogramming] Maximum Subarray Problem

2019-02-24 Thread 'Mike Day' via Programming
Sorry - correcting mxsasumcrude (below) - some brackets went missing. It should be mxsasumcrude =: >./@:(>./@:(+/\)\) Time and space much the same as below. Mike Here's what I previously posted, with inline correction... = Thanks to Raul f

Re: [Jprogramming] Maximum Subarray Problem

2019-02-24 Thread 'Mike Day' via Programming
Thanks to Raul for pointing out the Rosetta Stone entries at https://rosettacode.org/wiki/Greatest_subsequential_sum#J I tried    ts ' maxss q16' [q16 =: 2#8000$ ' but gave up waiting,  seeing Windows' Task Manager's display of total memory climbing towards 15GB. Then I spotted maxSS and m

Re: [Jprogramming] Maximum Subarray Problem

2019-02-24 Thread Raul Miller
Might be worth adding to https://rosettacode.org/wiki/Greatest_subsequential_sum#J ? Thanks, — Raul On Sunday, February 24, 2019, 'Jon Hough' via Programming < [email protected]> wrote: > Reference: https://en.wikipedia.org/wiki/Maximum_subarray_problem > > This is the problem: > Given

Re: [Jprogramming] Maximum Subarray Problem

2019-02-24 Thread 'Mike Day' via Programming
OK, Jon - I looked at wiki and implemented Kadane,  with mxsasum (explicit) and mxsasumt (tacit) returning just the best sum,  while mxsa returns the subarray. NB. Kadane's algorithm as presented in wiki NB. def max_subarray(A): NB. max_ending_here = max_so_far = A[0] NB. for x in A[1:

[Jprogramming] Maximum Subarray Problem

2019-02-24 Thread 'Jon Hough' via Programming
Reference: https://en.wikipedia.org/wiki/Maximum_subarray_problem This is the problem: Given an array of numbers, find the contiguous subset of maximum sum. i.e. find the maximum sum subarray. Example: R=: 3 4 _5 2 1 1 The maximum subarray is 3 4 Kadane's algorithm is a linear time algorithm to