Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
49
Task/N-queens-problem/EasyLang/n-queens-problem.easy
Normal file
49
Task/N-queens-problem/EasyLang/n-queens-problem.easy
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
subr show_sol
|
||||
print "Solution " & n_sol
|
||||
print ""
|
||||
for i = 1 to n
|
||||
write " "
|
||||
for j = 1 to n
|
||||
if j = x[i]
|
||||
write "Q "
|
||||
else
|
||||
write ". "
|
||||
.
|
||||
.
|
||||
print ""
|
||||
.
|
||||
print ""
|
||||
.
|
||||
subr test
|
||||
ok = 1
|
||||
for i = 1 to y - 1
|
||||
if x[y] = x[i] or abs (x[i] - x[y]) = abs (y - i)
|
||||
ok = 0
|
||||
.
|
||||
.
|
||||
.
|
||||
n = 8
|
||||
len x[] n
|
||||
y = 1
|
||||
x[1] = 1
|
||||
while y >= 1
|
||||
call test
|
||||
if ok = 1 and y + 1 <= n
|
||||
y += 1
|
||||
x[y] = 1
|
||||
else
|
||||
if ok = 1
|
||||
n_sol += 1
|
||||
if n_sol <= 1
|
||||
call show_sol
|
||||
.
|
||||
.
|
||||
while y >= 1 and x[y] = n
|
||||
y -= 1
|
||||
.
|
||||
if y >= 1
|
||||
x[y] += 1
|
||||
.
|
||||
.
|
||||
.
|
||||
print n_sol & " solutions"
|
||||
Loading…
Add table
Add a link
Reference in a new issue