This is what I meant originally, my J is still clumsy, i would
appreciate it if somebody made it more elegant.

NB. m h n - move element of n at m-th index to the end of the array
h1=:({,~]#~]~:{)"0 1
NB. same as above, only when m overshoots n prepend m to n
h2=:h1`([,])@.([>:#@:])
NB. The idea is to index the p(^!._1)n of draws of
NB. n elements from i.p without replacement, in the spirit
NB. of what A. does for permutations.
NB. So if i is a number from i.p(^!._1)n
NB. represented as I=:(>: (p - n) + i.n) #: i
NB. then p h3 I is the corresponding draw, and so is
NB. i h4 p n.
NB. h3 is quite inefficient, and the draws for subsequent
NB. i's are not in lexicographical order.
h3=:([EMAIL PROTECTED]@] {. [: h2/ ],[EMAIL PROTECTED]@[)"0 _
h4=:({.@:] h3 (#:~ >:@(-/) + i.@:{:))"0 _
NB. So to get m rows where each is n?p and no two rows
NB. are identical do
NB. (m?p(^!._1)n) h4 p n
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to