N Queens by tails

sub f{$a-$n?map{//;grep{grep$_==$a[$x]-$',0,$a-($x=$_),$_-$a}0..$a-1or$a[$a++]=$',f(),$a--}0..$n-1:print"@a
"}$n=<>;f

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

download

return to the top page