RosettaCodeData/Task/N-queens-problem/EasyLang/n-queens-problem.easy

50 lines
722 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
subr show_sol
2023-09-16 17:28:03 -07:00
print "Solution " & n_sol
print ""
for i = 1 to n
write " "
for j = 1 to n
if j = x[i]
write "Q "
else
write ". "
.
2023-07-01 11:58:00 -04:00
.
2023-09-16 17:28:03 -07:00
print ""
.
print ""
2023-07-01 11:58:00 -04:00
.
subr test
2023-09-16 17:28:03 -07:00
ok = 1
for i = 1 to y - 1
if x[y] = x[i] or abs (x[i] - x[y]) = abs (y - i)
ok = 0
.
.
2023-07-01 11:58:00 -04:00
.
n = 8
len x[] n
y = 1
x[1] = 1
while y >= 1
2023-09-16 17:28:03 -07:00
test
if ok = 1 and y + 1 <= n
y += 1
x[y] = 1
else
if ok = 1
n_sol += 1
if n_sol <= 1
show_sol
.
.
while y >= 1 and x[y] = n
y -= 1
.
if y >= 1
x[y] += 1
2023-07-01 11:58:00 -04:00
.
2023-09-16 17:28:03 -07:00
.
2023-07-01 11:58:00 -04:00
.
print n_sol & " solutions"