Joe Bogner wrote:
> +/ every ( (([: /:~ [: ? N&#) I. i.) </. #&1) Q
Yes, I. does seem germane to me, but I tried this verb and it seemed to
produce vectors of different lengths at each iteration. I need the result
to be exactly and always N numbers long, and their sum to be exactly and
always Q .
Marshall wrote:
> 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.
Thanks Marshall. The actual specification is
V is a vector of POSITIVE integers with shape N whose sum is Q.
That is: there must be exactly N buckets, and no bucket may be empty. All
possible ordered series of buckets must be equally likely.
Pascal wrote:
> Maybe show some valid vectors for small Q?
For example [1], for N=3 and Q=7
1 1 5
1 2 4
1 3 3
1 4 2
1 5 1
2 1 4
2 2 3
2 3 2
2 4 1
3 1 3
3 2 2
3 3 1
4 1 2
4 2 1
5 1 1
A very regular pattern, now that I look at it. If we knew the number ZFNP
of possible 0-free N-partitions an integer Q, then we'd only have to roll
?ZFNP and then figure out some function analogous to #: to break it apart
into its constituents.
REB wrote:
> V=: Q*(%+/) 2 rnd N ?@# 0
This looks promising. What's rnd here?
Bob wrote:
> Probably a converging power conjunction
Ideally, I'm looking for an instantaneous / closed form solution, one which
avoids iteration or recurision, if possible.
-Dan
[1] I created this table by hand, but it looks right.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm