Python 3.8 (pre-release), 264 250 121120 + 121120 = 242240 bytes
Code 0: (121120 bytes)
for i in(c:=[]),0:
c+=0,;exec(s:="i or print(end=f'for i in(c:=[]),0:\\n c+={c.pop()^allc[0]^all(c:=c[1:]-1])},;exec(s:=%r)#'%s)")#
Code 1: (121120 bytes)
for i in(c:=[]),0:
c+=1,;exec(s:="i or print(end=f'for i in(c:=[]),0:\\n c+={c.pop()^allc[0]^all(c:=c[1:]-1])},;exec(s:=%r)#'%s)")#
Test Suite
How it works:
cstore the binary number of the program on the form of a list
The for loop execute twice :
- the first time, it assigns
cto the correct value - the second time, it prints the code replacing a char by 1 or 0 depending on
c. Thenth timec.pop()^allc[0]^all(c:=c[1:]-1])is called, it returns thenth leftmost bit ofc+1
the next for loop are ignored thanks to the comment #
The printing is a derivate of this quine : exec(s:="print('exec(s:=%r)'%s)")