This solution leaves out all the zeros in V, so you might end up with a
short vector.

The interpretation of the original problem that I would use is: V is a
vector of nonnegative integers with shape N whose sum is Q, and each
such vector has an equal probability of being chosen. Unfortunately, the
approach here makes answers with a zero less likely, because there are
fewer sequences which, when sorted, have adjacent terms which are equal
(that is, the sequences 3 5 and 5 3 both turn into 3 5, but only 3 3
turns into 3 3 when sorted).

To get the correct probabilities, you need dyad (?):

   N ([: <: 2 -~/\ <:@[ (0 , /:~@:? , ]) +) Q
15 16 10 6 14 24 0 4 3 8

In order to ensure that zeros are possible in the result, I first added
N to Q, and then subtracted one from each value in the result.

Marshall

On Fri, May 08, 2015 at 12:25:13PM -0400, Joe Bogner wrote:
> what about this?
> 
> Q=: 100
> N=: 10
> 
> +/ +/ every ( (([: /:~ [: ? N&#) I. i.) </. #&1) Q
> 
> 100
> 
> 
> 
> 
> On Fri, May 8, 2015 at 11:54 AM, Dan Bron <[email protected]> wrote:
> > I have a quantity Q and I want to divide it into a vector V of N
> > randomly-sized chunks, such that N=#V and Q=+/V .
> >
> > Ideas?
> >
> > -Dan
> >
> >
> >
> >
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to