how to generate all possible combinations of a 14x10 matrix containing only 1's and 0's

前端 未结 11 1002
悲&欢浪女
悲&欢浪女 2021-01-23 23:32

I\'m working on a problem and one solution would require an input of every 14x10 matrix that is possible to be made up of 1\'s and 0\'s... how can I generate these so that I can

11条回答
  •  北海茫月
    2021-01-23 23:59

    You don't have to iterate over this:

    def everyPossibleMatrix(x,y):
        N=x*y
        for i in range(2**N):
            b="{:0{}b}".format(i,N)
            yield '\n'.join(b[j*x:(j+1)*x] for j in range(y))
    

提交回复
热议问题