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

Reply via email to