Gray code by jonathan camacho

$l=<>;@L=([(0)x$l]);for$i(0..($l-1)){$x=$l-1-$i;for(@L){$$_[$x]=0}
for(reverse(@L)){push(@L,[@$_]);$L[$#L][$x]=1}}print("Gray code  n=$l");for(@L){print(join("",@$_)."\n")}

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

download

return to the top page