>I believe this will work:
>
> sbt =: I.&|. +//. ]
First, it should've been:
sbt =: (I.~ |.)~ +//. ]
Second. I guess the length and order of the results from this is
data-dependent.
The following version is much longer and uglier than the original, but produces
the correct result independent of the length and order of the data, and even
correctly handles data that is not stricly bounded by [m,n] .
interval =. (> {:)~ + <:@:#@:[ - (I.~ |.)~
range =. interval ,~ _1 , i.@:>:@:#@:[
values =. (,~ 0 #~ 2 + #)~
rsums =. range +//. values
sbt =: }.@:}:@rsums f.
This could be made simpler and more efficient if you guaruntee that your data
is clamped to [0,n) or (0,n] (particularly the latter).
-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm