and =: 17 b. xor =: 22 b. or =: 23 b. shift=: 33 b. nc=: 3 : 0 n=. y t=. n xor n and n-1 b=. t+n b or _2 shift (b xor n) <[EMAIL PROTECTED] t )
#: nc^:(i.3!5) 7 0 0 1 1 1 0 1 0 1 1 0 1 1 0 1 0 1 1 1 0 1 0 0 1 1 1 0 1 0 1 1 0 1 1 0 1 1 0 0 1 1 1 0 1 0 1 1 1 0 0 I."1 #: nc^:(i.3!5) 7 2 3 4 1 3 4 1 2 4 1 2 3 0 3 4 0 2 4 0 2 3 0 1 4 0 1 3 0 1 2 (3 comb 5) -: |. I."1 #: nc^:(i.3!5) 7 1 ----- Original Message ----- From: Andrew Nikitin <[EMAIL PROTECTED]> Date: Tuesday, August 28, 2007 6:26 Subject: [Jprogramming] Permutations of a sort. To: [email protected] > Ralph, I am not sure if you know this trick or not, but if you > start with > interger (n) whose binary representation contains exactly k ones then > { int t,b; > t=n^(n&(n-1)); > b=t+n; > n=b|(((b^n)/t)>>2); > } > generates next larger number with exactly k ones. As long as you > stay within > int size (in your case with 28 elements you do) it is a decent method. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
