Gray code by Sasa

a=input()
print"Gray code  n="+`a`
for i in range(2**a):
 s='';y=a+1
 while y-1:u=2**y;y-=1;s+=`1*(u/4<=i%u<3*u/4)`
 print s

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page