On 31 Oct 2006 at 7:39, Leigh J. Halliwell said:

> Dear J Forum:
> 
> Given a vector X of n atoms, and a partition P of non-negative integers
> that sum to n; i.e. n = n1+n2+...+nk, how can I efficiently create a list
> of k items, whose first atom is the box of the first n1 elements of X,
> whose second atom is the box of the next n2 elements, etc?  Empty boxes
> (ni=0) must be allowed.  I can do this with difficulty; but I suppose that
> J primitives allow it to be done as a one-line tacit dyadic function X
> BoxAccTo P.  Thanks.

  ((+/\*])0<P){a:(I.P)</.X
seems to work, and
   13 :'((+/\*])0<y){a:,(I.y)</.x'
([: (+/\ * ]) 0 < ]) { a: , [ </.~ [: I. ]
though I'd be surprised if that can't be improved upon.

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

Reply via email to