I’m looking for (but haven’t found yet) a way to save the solutions of the 8 queens problem on a chessboard into an array of some sort, without necessarily having to “print” them live.
If possible by changing the following functions. But it’s also fine with a completely different setting.
for the moment my workaround is this
function safe(queen, row)
for i in 1:queen-1
xriga = T[i]
if (xriga == row||
xriga == row- (queen- i) ||
xriga == row+ (queen- i))
return false
end
end
return true
end
function try(k)
if (k <= 8)
for i in 1:8
if (safe(k, i))
T[k] = i
try(k + 1)
end
end
else
for i in 1:8
print(io,T[i],' ')
end
print(io,'\n')
end
end
io=IOBuffer();
T=fill(0,8)
res=Vector{Vector{Int}}()
try(1)
sol=take!(io)
reshape(sol,17,:)'[:,1:2:16].-48