N Queens by murky-satyr

n=io.read'*n'q=function(o)for x=0,n-1 do
f=1
for i=0,#o-1 do v=x-o[#o-i]f=f*v*(v^2-(i-#o)^2)end
t=f==0 or q{x,unpack(o)}end
t=#o~=n or print(table.concat(o,' '):reverse())end
q{}

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

download

return to the top page