generating 2D bit array variants with specific algorythm

ast nomail at invalid.com
Fri Nov 7 11:57:10 EST 2014


"Robert Voigtländer" <r.voigtlaender at gmail.com> a écrit dans le message de 
news:0e6787f9-88d6-423a-8410-7578fa83d61c at googlegroups.com...

Let be L the number of lines and C the numbers of column

You solve your problem just with counting on base C

On base C, a number may be represented with

N(L-1)N(L-2) ... N(0)N(0) where N(i) goes from 0 to C-1

N(i) is associated with line i of your array. Lines are numbered from 0
if N(i) == j, then bit in column j of line i is 1 and all others 0, columns are numbered from 0

For example, with an array of 2 lines and 3 colums

00 -->

100 <  line 1
100  < line 0

01 ->

100
010

02 ->

100
001

10 ->

010
100

11 ->

010
010

12 ->

010
001

20 ->

001
100

21 ->

001
010

22 ->

001
001









More information about the Python-list mailing list