N Queens by yowa

n=gets.to_i
r=proc{|a,y,z|y<n ?n.times{|x|z&(c=(1|1<<y+9|1<<30-y)<<x)<1&&r[a+[x],y+1,z|c]}:puts(a*" ")}
r[[],0,0]

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

download

return to the top page