The combination index is a good way to get the "next"
combination or binary string. e.g.

   14 28 ci 0
0 1 2 3 4 5 6 7 8 9 10 11 12 13
   (i.28) e. 14 28 ci 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   (i.28) e. 14 28 ci 1
1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
   (i.28) e. 14 28 ci 2
1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
   
   (i.28) e. 14 28 ci _2+14!28x
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1
   (i.28) e. 14 28 ci _1+14!28x
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1



----- Original Message -----
From: Roger Hui <[EMAIL PROTECTED]>
Date: Monday, August 27, 2007 14:00
Subject: Re: [Jprogramming] Permutations of a sort.
To: Programming forum <[email protected]>

> There are k!n binary strings of length n with k 1s,
> and (i.n) e."1 k comb n are all such strings. e.g.
> 
>    4 comb 6
> 0 1 2 3
> 0 1 2 4
> 0 1 2 5
> 0 1 3 4
> 0 1 3 5
> 0 1 4 5
> 0 2 3 4
> 0 2 3 5
> 0 2 4 5
> 0 3 4 5
> 1 2 3 4
> 1 2 3 5
> 1 2 4 5
> 1 3 4 5
> 2 3 4 5
>    (i.6) e."1 ]4 comb 6
> 1 1 1 1 0 0
> 1 1 1 0 1 0
> 1 1 1 0 0 1
> 1 1 0 1 1 0
> 1 1 0 1 0 1
> 1 1 0 0 1 1
> 1 0 1 1 1 0
> 1 0 1 1 0 1
> 1 0 1 0 1 1
> 1 0 0 1 1 1
> 0 1 1 1 1 0
> 0 1 1 1 0 1
> 0 1 1 0 1 1
> 0 1 0 1 1 1
> 0 0 1 1 1 1
> 
> See:
> 
> http://www.jsoftware.com/jwiki/Essays/Combinations
> http://www.jsoftware.com/jwiki/Essays/Combination_Index
> 
> 
> 
> ----- Original Message -----
> From: Ralph G Selfridge <[EMAIL PROTECTED]>
> Date: Monday, August 27, 2007 13:24
> Subject: [Jprogramming] Permutations of a sort.
> To: [email protected]
> 
> > Here's my problem. I have a binary string, potentially long, 
> in 
> > my case 
> > 28. I need to get all binary strings with a specified number 
> of 
> > 1s. I doubt 
> > I can get them all at once, too many, so how do I get from one 
> > to the next?
> > 
> > What next means is irrelvant, just so I get them with no 
> > duplicates if I 
> > run long emough.
> > 
> > While I have an answer, I'm curious to see if there is a 
> better way.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to