RosettaCodeData/Task/N-queens-problem/Draco/n-queens-problem.draco
2023-07-01 13:44:08 -04:00

38 lines
877 B
Text

byte SIZE = 8;
word count;
proc solve([*] int hist; int col) void:
int i, j, n;
n := dim(hist, 1);
if col = n then
count := count + 1;
writeln();
writeln("No. ", count);
writeln("-----");
for i from 0 upto n-1 do
for j from 0 upto n-1 do
write(if j=hist[i] then 'Q'
elif (i+j)&1 /= 0 then ' '
else '.' fi)
od;
writeln()
od
else
for i from 0 upto n-1 do
j := 0;
while j<col and not (hist[j]=i or |(hist[j]-i) = col-j) do
j := j + 1
od;
if j >= col then
hist[col] := i;
solve(hist, col+1)
fi
od
fi
corp
proc nonrec main() void:
[SIZE] int hist;
count := 0;
solve(hist, 0)
corp