Hello Andrew;
What happens if the running sum vector overflows?
------------------------------------------------------------------------
|\/| Randy A MacDonald | APL: If you can say it, it's done.. (ram)
|/\| [EMAIL PROTECTED] |
|\ | |If you cannot describe what you are doing
BSc(Math) UNBF'83 þas a process, you don't know what you're doing.
Sapere Aude | - W. E. Deming
Natural Born APL'er | Demo website: http://156.34.81.55/
-----------------------------------------------------(INTP)----{ gnat }-
----- Original Message -----
From: "Andrew Nikitin" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, July 11, 2006 3:09 AM
Subject: [Jprogramming] Musings on permutation vectors
bill lam:
how the write to the first one (+//.) using APL style?
As Dan showed there is more than one way to skin a cat. However, I frown
upon = because of potential quadratic performance.
1 2 3 4 5 (+//.)~ 2 1 2 1 2
9 6
t-0,}:t=.(1|.t=.1,(}:t)~:}.t=./:~i)#+/\1 2 3 4 5/:i=.i.~2 1 2 1 2
9 6
First you rearrange values so that numbers from same froup follow each
other
and group go in their nub order. Then you get running sum vector and
reduce
it with boolean vector containing 1's at groups' end. End of each group is
sum of elements of this group and all previous groups. Finally, you
subtract
"previous groups sums" to get sums.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm