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)

7 comments

0

LOL, just gonna delete your last question after i answer it.

0

No. You didn't.

0

You helped me on the end but not this one.

0

Yes, but after i answered your last question, you edited it to ask a different question and asked for more help.

0

then i said ask another question then, so you deleted the other one.

0

w/e, just saying, bad manners.

0

yes I asked this on. I assumed you meant to delete it then make a new one. Was I wrong?