|
|
DataMuseum.dkPresents historical artifacts from the history of: Rational R1000/400 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Rational R1000/400 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 9216 (0x2400)
Types: Ada Source
Notes: 03_class, FILE, R1k_Segment, e3_tag, package body Magic_Square, seg_03dfee
└─⟦8527c1e9b⟧ Bits:30000544 8mm tape, Rational 1000, Arrival backup of disks in PAM's R1000
└─⟦cfc2e13cd⟧ »Space Info Vol 2«
└─⟦this⟧
with Io;
with Text_Io;
package body Magic_Square is
procedure Move (D : Direction;
Row_Position : in out Integer;
Col_Position : in out Integer;
Tab_Size : in out Integer) is
begin
case D is
when Sud_Ouest =>
Row_Position := ((Row_Position + 1) mod (Tab_Size + 1));
if Row_Position = 0 then
Row_Position := 1;
end if;
Col_Position := Col_Position - 1;
if Col_Position = 0 then
Col_Position := Tab_Size;
end if;
when Nord_Est =>
Row_Position := Row_Position - 1;
if Row_Position = 0 then
Row_Position := Tab_Size;
end if;
Col_Position := ((Col_Position + 1) mod (Tab_Size + 1));
if Col_Position = 0 then
Col_Position := 1;
end if;
when Nord_Ouest =>
Row_Position := Row_Position - 1;
if Row_Position = 0 then
Row_Position := Tab_Size;
end if;
Col_Position := Col_Position - 1;
if Col_Position = 0 then
Col_Position := Tab_Size;
end if;
when Nord =>
Row_Position := Row_Position - 1;
if Row_Position = 0 then
Row_Position := Tab_Size;
end if;
when others =>
null;
end case;
end Move;
procedure Go_To_Center (Row_Position : in out Integer;
Col_Position : in out Integer;
Tab_Size : Integer) is
begin
Row_Position := Tab_Size / 2 + 1;
Col_Position := Tab_Size / 2 + 1;
end Go_To_Center;
procedure Init_Square (Row_Position : in out Integer;
Col_Position : in out Integer;
Tab_Size : Integer) is
I : Integer;
J : Integer;
begin
for I in 1 .. Tab_Size loop
for J in 1 .. Tab_Size loop
Tab (I, J) := 0;
end loop;
end loop;
Go_To_Center (Row_Position, Col_Position, Tab_Size);
end Init_Square;
procedure Affichage (Tab_Size : Integer) is
I, J : Integer;
begin
Text_Io.Put (" |-");
for I in 1 .. (Tab_Size * 2 - 1) loop
Text_Io.Put ("---");
end loop;
Text_Io.Put_Line ("-| ");
for I in 1 .. Tab_Size loop
Text_Io.Put (" | ");
for J in 1 .. Tab_Size loop
Io.Put (Tab (I, J), Width => 3);
Text_Io.Put (" | ");
end loop;
Text_Io.Put_Line ("");
Text_Io.Put (" |-");
for I in 1 .. (Tab_Size * 2 - 1) loop
Text_Io.Put ("---");
end loop;
Text_Io.Put_Line ("-|");
end loop;
end Affichage;
procedure Calcul_Tableau (Row_Position : in out Integer;
Col_Position : in out Integer;
Tab_Size : in out Integer) is
I, J, Token : Integer;
Tab_Capacity : Integer := Tab_Size * Tab_Size;
Dir : Direction;
begin
Token := 1;
Dir := Nord;
Move (Dir, Row_Position, Col_Position, Tab_Size);
Tab (Row_Position, Col_Position) := Token;
Dir := Nord_Est;
Token := Token + 1;
Move (Dir, Row_Position, Col_Position, Tab_Size);
while Token <= Tab_Capacity loop
if Tab (Row_Position, Col_Position) = 0 then
Tab (Row_Position, Col_Position) := Token;
Token := Token + 1;
Dir := Nord_Est;
Move (Dir, Row_Position, Col_Position, Tab_Size);
else
Dir := Sud_Ouest;
Move (Dir, Row_Position, Col_Position, Tab_Size);
Dir := Nord_Ouest;
Move (Dir, Row_Position, Col_Position, Tab_Size);
Dir := Nord_Est;
Move (Dir, Row_Position, Col_Position, Tab_Size);
end if;
end loop;
end Calcul_Tableau;
procedure Run (Tab_Size : in out Integer) is
Row_Position : Integer;
Col_Position : Integer;
begin
Init_Square (Row_Position, Col_Position, Tab_Size);
Go_To_Center (Row_Position, Col_Position, Tab_Size);
Calcul_Tableau (Row_Position, Col_Position, Tab_Size);
Affichage (Tab_Size);
end Run;
procedure Run2 is
Nombre_Pair, Nombre_Trop_Grand : exception;
Test : Integer;
Tab_Size : Integer := 5;
begin
Gogo:
loop
Text_Io.Put_Line ("Donnez la taille du tableau");
Io.Get (Tab_Size);
if Tab_Size >= 100 then
raise Nombre_Trop_Grand;
exit Gogo;
end if;
Test := (Tab_Size mod 2);
if (Test = 0) then
Text_Io.Put_Line ("Nombre_Pair");
raise Nombre_Pair;
exit Gogo;
end if;
Text_Io.Put_Line ("");
Run (Tab_Size);
Text_Io.Put_Line ("");
end loop Gogo;
Text_Io.Put_Line ("Out Loop");
exception
when Nombre_Trop_Grand =>
Text_Io.Put_Line ("Exception : array overflow");
when Nombre_Pair =>
Text_Io.Put_Line ("Exception : array size must be odd");
when others =>
Text_Io.Put_Line ("Fatal error");
end Run2;
end Magic_Square;
nblk1=8
nid=5
hdr6=e
[0x00] rec0=1b rec1=00 rec2=01 rec3=032
[0x01] rec0=1f rec1=00 rec2=06 rec3=010
[0x02] rec0=20 rec1=00 rec2=03 rec3=01c
[0x03] rec0=1b rec1=00 rec2=04 rec3=004
[0x04] rec0=1b rec1=00 rec2=08 rec3=004
[0x05] rec0=1b rec1=00 rec2=07 rec3=00e
[0x06] rec0=02 rec1=00 rec2=02 rec3=000
[0x07] rec0=88 rec1=5f rec2=76 rec3=580
tail 0x2173d3c2885fd74ce2372 0x42a00088462060003
Free Block Chain:
0x5: 0000 00 00 00 a9 80 03 65 29 3b 03 00 22 20 20 20 20 ┆ e); " ┆