with Ada.Text_Io, Ada.Integer_Text_Io;
use Ada.Text_Io, Ada.Integer_Text_Io;
procedure Exo2 is
type T_Echiquier is array(1..8, 1..8) of Boolean;
procedure Interdit_Ligne(I : in Integer; E : out T_Echiquier) is
begin
for J in 1..8 loop
E(I, J) := True;
end loop;
end Interdit_Ligne;
procedure Interdit_Colonne(I : in Integer; E : out T_Echiquier) is
begin
for J in 1..8 loop
E(J, I) := True;
end loop;
end Interdit_Colonne;
procedure Interdit_Diagonale(I, J : in Integer; E : out T_Echiquier) is
X, Y : Integer;
begin
X := I; Y := J;
while X <= 8 and Y <= 8 loop
E(X, Y) := True;
X := X + 1;
Y := Y + 1;
end loop;
X := I; Y := J;
while X >= 1 and Y <= 8 loop
E(X, Y) := True;
X := X - 1;
Y := Y + 1;
end loop;
X := I; Y := J;
while X <= 8 and Y >= 1 loop
E(X, Y) := True;
X := X + 1;
Y := Y - 1;
end loop;
X := I; Y := J;
while X >= 1 and Y >= 1 loop
E(X, Y) := True;
X := X - 1;
Y := Y - 1;
end loop;
end Interdit_Diagonale;
function Ajoute_Reine(L : in Integer; E : in T_Echiquier) return Integer is
Res : Integer := 0;
Ebis : T_Echiquier;
begin
if L = 9 then return 1; end if;
for I in 1..8 loop
if not E(L, I) then
Ebis := E;
Interdit_Ligne(L, Ebis);
Interdit_Colonne(I, Ebis);
Interdit_Diagonale(L, I, Ebis);
Res := Res + Ajoute_Reine(L + 1, Ebis);
end if;
end loop;
return res;
end Ajoute_Reine;
Echiquier : T_Echiquier := (others => (others => False));
Nb_Solutions : Integer;
begin
Nb_Solutions := Ajoute_Reine(1, Echiquier);
Put(Nb_Solutions);
end Exo2;