generating 2D bit array variants with specific algorythm

Dave Angel davea at davea.name
Fri Nov 7 20:34:11 CET 2014


Robert Voigtländer <r.voigtlaender at gmail.com> Wrote in message:
> Hi,
> 
> I need to generate all variants of a 2D array with variable dimension sizes which fit a specific rule. (up to 200*1000)
> 
> The rules are:
> - Values are only 0 or 1
> - the sum of each line bust be 1
> - only valid results must be generated (generating all and only returning the valid results takes to long; that's what I tried already)
> 
> So for a 2x2 array these would be the valid results:
> 
> 10
> 01
> 
> 01
> 10
> 
> 10
> 10
> 
> 01
> 01
> 
> 
> Must be possible with nested loops and a counter per line. But I don't get it.

If the matrix is m by n, then there are 2**n possibilities for
 each row. But only n of them are legal by your rules. So your
 problem is just a matter of counting in base n, all the possible
 m digit numbers.


-- 
DaveA




More information about the Python-list mailing list