N Queens by 51b

n,l,k;char s[99];f(i,j){for(i/2-n+j?s[i-1]=32:puts(s);k=j<n;s[i]=j++,k&&f(i+2,48))for(l=i;l--;)k&=s[--l]-j&&abs(s[l]-j)*2-i+l;}main(){n=getchar();f(0,48);}

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

download

return to the top page