5: attempt to perform arithmetic on field '?' (a nil value)?
N = 8 --board size
--make sure place (n,c) is away from attacks
function isplaceok (a, n, c)
if (a[i] == c) or
(a[i] - i == c - n) or
(a[i] + i == c + n) then
return false
end
return true
end
function printsolution (a)
for i = 1, N do
for j = 1, N do
io.write(a[i] == j and "x" or "_", " ")
end
io.write("\n")
end
io.write("\n")
end
function addqueen (a,n)
if n > N then
printsolution(a)
else
for c = 1, N do
if isplaceok(a, n, c) then
a[n] = c
addqueen (a, n + 1)
end
end
end
end
addqueen({}, 1)