with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Labo2 is
subtype T_Nombre is Positive range 1..19;
type T_Hexagone is array (Natural range T_Nombre'Range) of Natural;
Hexagone : T_Hexagone;
Resultats : Integer := 0;
NOMBRE_MAGIQUE : constant := 38;
procedure Afficher (Hexagone :in T_Hexagone) is
begin -- Afficher
for I in Hexagone'Range loop
Put(Hexagone(I), 0);
put(',');
end loop;
end Afficher;
function Est_Utilise (Hexagone : in T_Hexagone;
Cellule : in T_Nombre;
Nombre : in T_Nombre) return boolean is
begin -- Est_Utilise
for I in 1..Cellule loop
if Hexagone(I) = Nombre then
return true;
end if;
end loop;
return false;
end Est_Utilise;
function Verification (Hexagone : in T_Hexagone;
Cellule : in T_Nombre) return boolean is
begin -- Verification
-- Put("Verification cas ");
-- Put(Cellule,0);
-- New_Line;
case Cellule is
when 3 =>
return Hexagone(1) + Hexagone(2) + Hexagone(3) = NOMBRE_MAGIQUE;
when 7 =>
return Hexagone(4) + Hexagone(5) + Hexagone(6) + Hexagone(7) = NOMBRE_MAGIQUE;
when 8 =>
return Hexagone(1) + Hexagone(4) + Hexagone(8) = NOMBRE_MAGIQUE;
when 12 =>
return Hexagone(8) + Hexagone(9) + Hexagone(10) + Hexagone(11) + Hexagone(12) = NOMBRE_MAGIQUE and
Hexagone(3) + Hexagone(7) + Hexagone(12) = NOMBRE_MAGIQUE;
when 13 =>
return Hexagone(2) + Hexagone(5) + Hexagone(9) + Hexagone(13) = NOMBRE_MAGIQUE;
when 16 =>
return Hexagone(13) + Hexagone(14) + Hexagone(15) + Hexagone(16) = NOMBRE_MAGIQUE and
Hexagone(2) + Hexagone(6) + Hexagone(11) + Hexagone(16) = NOMBRE_MAGIQUE;
when 17 =>
return Hexagone(3) + Hexagone(6) + Hexagone(10) + Hexagone(14) + Hexagone(17) = NOMBRE_MAGIQUE and
Hexagone(8) + Hexagone(13) + Hexagone(17) = NOMBRE_MAGIQUE;
when 18 =>
return Hexagone(7) + Hexagone(11) + Hexagone(15) + Hexagone(18) = NOMBRE_MAGIQUE and
Hexagone(4) + Hexagone(9) + Hexagone(14) + Hexagone(18) = NOMBRE_MAGIQUE;
when 19 =>
return Hexagone(1) + Hexagone(5) + Hexagone(10) + Hexagone(15) + Hexagone(19) = NOMBRE_MAGIQUE and
Hexagone(12) + Hexagone(16) + Hexagone(19) = NOMBRE_MAGIQUE and
Hexagone(17) + Hexagone(18) + Hexagone(19) = NOMBRE_MAGIQUE;
when others =>
return true;
end case;
end Verification;
procedure Resolution (Hexagone : in out T_Hexagone;
Cellule : in T_Nombre;
Resultats : in out Integer) is
begin -- Resolution
for I in T_Nombre'Range loop
if not Est_Utilise(Hexagone, Cellule, I) then
Hexagone(Cellule) := I;
if Verification(Hexagone, Cellule)then
if Cellule = 19 then
Resultats := Resultats + 1;
--Put(Resultats,0);
Afficher(Hexagone);
New_Line;
else
Resolution(Hexagone, Cellule + 1, Resultats);
end if;
end if;
end if;
end loop;
end Resolution;
begin -- Labo2
Resolution (Hexagone, 1, Resultats);
Put(Resultats);
Skip_Line;
end Labo2;