N Queens by hirose

n=input()
def f(m):
\x09x=[];l=len(m)
\x09if l==n:print" ".join(`m`[1::3])
\x09for t in m:x+=[t,t-l,t+l];l-=1
\x09for i in set(range(n))-set(x):f(m+[i])
f([])

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

download

return to the top page