> From: "Randy MacDonald"
> What happens if the running sum vector overflows?

Randy, nothing good will happen. Also there can be some significant loss of
precision -- which is worse because more difficult to notice. Do you know
better way?

Dan Bron wrote:
> Ok, if I'm not allowed to filter-and-operate (because of the space/time
> required by the boolean vectors), then, for  ; b <@/:~;.1 values  :
>
>    b (] /: (10x ^ +/\)@:[ + /:@:/:@:]) values

Not trying to be picky or something, but this does not work for
   b=.(1|.101{.1 1) [ values=.(i.100),0
   _5{. b (] /: (10x ^ +/\)@:[ + /:@:/:@:]) values
95 96 97 98 99
   _5{. ;b <@/:~;.1 values
96 97 98 99 0

Algorithm of choice here is something that is nowadays called "bitsort"
Algorithm itself dates back into the days of perforated cards. and I do not
mean those modern high tech 45 column (or even 80 column) perforated cards
for use with electronic computing devices. I mean cards with edge
perforation.

   ]values=.?.15$100
46 55 79 52 54 39 60 57 60 94 46 78 13 18 51
   ]b=.1,0=?.14$4
1 0 0 0 1 0 0 1 0 1 0 0 0 0 0
   (i{+/\b)/:~values{~i=./:values
46 52 55 79 39 54 60 57 60 13 18 46 51 78 94
   ; b <@/:~;.1 values
46 52 55 79 39 54 60 57 60 13 18 46 51 78 94

If you want to sort array of 2-digit numbers you first sort it by last digit
and then sort the result by first digit. Here, first "digit" is "group
number" and second "digit" is value itself. Algorithm is pretty obvious, but
somehow comes as a surprise for many people,

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to