Data update

This commit is contained in:
Ingy döt Net 2024-07-13 15:19:22 -07:00
parent 29a5eea0d4
commit 5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions

View file

@ -1,81 +1,34 @@
program queens;
program eightqueens(output);
var i: integer;
a: array [1..8] of boolean; { a[j]: no queen in row j }
b: array [2..16] of boolean; { b[k]: no queen in kth diagonal down-left }
c: array [-7..7] of boolean; { c[k]: no queen in kth diagonal down-right }
x: array [1..8] of integer; { x[i]: position of queen in column i }
procedure print;
var k: integer;
begin
for k := 1 to 8 do write(x[k]: 4);
writeln
end { print } ;
const l=16;
var i,j,k,m,n,p,q,r,y,z: integer;
a,s: array[1..l] of integer;
u: array[1..4*l-2] of integer;
label L3,L4,L5,L6,L7,L8,L9,L10;
procedure try(i: integer);
var j: integer;
begin
for j := 1 to 8 do
if a[j] and b[i+j] and c[i-j] then
begin
{ place queen }
x[i] := j;
a[j] := false; b[i+j] := false; c[i-j] := false;
if i < 8 then try(i+1) else print;
{ remove queen }
a[j] := true; b[i+j] := true; c[i-j] := true
end
end { try } ;
begin
for i:=1 to l do a[i]:=i;
for i:=1 to 4*l-2 do u[i]:=0;
for n:=1 to l do
begin
m:=0;
i:=1;
r:=2*n-1;
goto L4;
L3:
s[i]:=j;
u[p]:=1;
u[q+r]:=1;
i:=i+1;
L4:
if i>n then goto L8;
j:=i;
L5:
z:=a[i];
y:=a[j];
p:=i-y+n;
q:=i+y-1;
a[i]:=y;
a[j]:=z;
if (u[p]=0) and (u[q+r]=0) then goto L3;
L6:
j:=j+1;
if j<=n then goto L5;
L7:
j:=j-1;
if j=i then goto L9;
z:=a[i];
a[i]:=a[j];
a[j]:=z;
goto L7;
L8:
m:=m+1;
{ uncomment the following to print solutions }
{ write(n,' ',m,':');
for k:=1 to n do write(' ',a[k]);
writeln; }
L9:
i:=i-1;
if i=0 then goto L10;
p:=i-a[i]+n;
q:=i+a[i]-1;
j:=s[i];
u[p]:=0;
u[q+r]:=0;
goto L6;
L10:
writeln(n,' ',m);
end;
end.
{ 1 1
2 0
3 0
4 2
5 10
6 4
7 40
8 92
9 352
10 724
11 2680
12 14200
13 73712
14 365596
15 2279184
16 14772512 }
for i := 1 to 8 do a[i] := true;
for i := 2 to 16 do b[i] := true;
for i := -7 to 7 do c[i] := true;
try(1)
end .