Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
34
Task/N-queens-problem/Maple/n-queens-problem.maple
Normal file
34
Task/N-queens-problem/Maple/n-queens-problem.maple
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
queens:=proc(n)
|
||||
local a,u,v,m,aux;
|
||||
a:=[$1..n];
|
||||
u:=[true$2*n-1];
|
||||
v:=[true$2*n-1];
|
||||
m:=[];
|
||||
aux:=proc(i)
|
||||
local j,k,p,q;
|
||||
if i>n then
|
||||
m:=[op(m),copy(a)];
|
||||
else
|
||||
for j from i to n do
|
||||
k:=a[j];
|
||||
p:=i-k+n;
|
||||
q:=i+k-1;
|
||||
if u[p] and v[q] then
|
||||
u[p]:=false;
|
||||
v[q]:=false;
|
||||
a[j]:=a[i];
|
||||
a[i]:=k;
|
||||
aux(i+1);
|
||||
u[p]:=true;
|
||||
v[q]:=true;
|
||||
a[i]:=a[j];
|
||||
a[j]:=k;
|
||||
fi;
|
||||
od;
|
||||
fi;
|
||||
end;
|
||||
aux(1);
|
||||
m
|
||||
end:
|
||||
|
||||
for a in queens(8) do printf("%a\n",a) od;
|
||||
Loading…
Add table
Add a link
Reference in a new issue