Gray code by Patashu

class D{public static void main(String[]_)throws Exception{int i=0,j=0,k=0,n=System.in.read()%8,g[]=new int[128];System.out.println("Gray code  n="+n);for(g[0]=0;i<Math.pow(2,n);j--){g[i]=g[j]|k;String s="000000"+Long.toBinaryString(g[i]);System.out.println(s.substring(s.length()-n));if((i&++i)==0)k=j=i;}}}

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

download

return to the top page