from itertools import combinations
def solve(n):
seq = [[0] * n]
while 1:
m = (1 << n) - 1
for p in range(1, n // 2 + 1):
l = 2 * p
for c in combinations(range(n), r=l):
lst = seq[-1][:]
k = int(''.join(map(str, lst)), 2)
for i in c:
lst[i] = 1 - lst[i]
x = int(''.join(map(str, lst)), 2)
if k < x <= m:
m = x
nxt = lst[:]
if all(x == y for x, y in zip(nxt, seq[-1])):
break
seq.append(nxt[:])
return seq
'''
00
11
##############
0 00
0 11
1 01
1 10
##############
00 00
00 11
01 01
01 10
10 01
10 10
11 00
11 11
##############
0 0000
0 0011
0 0101
0 0110
0 1001
0 1010
0 1100
0 1111
1 0001
1 0010
1 0100
1 0111
1 1000
1 1011
1 1101
1 1110
#############
00 0000
00 0011
00 0101
00 0110
00 1001
00 1010
00 1100
00 1111
01 0001
01 0010
01 0100
01 0111
01 1000
01 1011
01 1101
01 1110
10 0001
10 0010
10 0100
10 0111
10 1000
10 1011
10 1101
10 1110
11 0000
11 0011
11 0101
11 0110
11 1001
11 1010
11 1100
11 1111'''
r = solve(2)
for x in r:
print(''.join(map(str, x)))
To embed this program on your website, copy the following code and paste it into your website's HTML: