-- $Id: ary3.gnat,v 1.0 2003/06/11 12:08:00 dada Exp $
-- http://dada.perl.it/shootout/
-- Ada 95 code by C.C.
with Text_IO, Ada.Command_Line, Ada.Strings.Fixed;
procedure Ary3 is
function L_Trim (Source : String; Side : Ada.Strings.Trim_End :=
Ada.Strings.Left) return String renames Ada.Strings.Fixed.Trim;
N : Positive := 1;
begin
begin
N := Positive'Value (Ada.Command_Line.Argument (1));
exception
when Constraint_Error => null;
end;
declare
type Vect is array (1 .. N) of Integer;
X, Y : Vect;
begin
for K in Vect'Range loop
X (K) := K;
Y (K) := 0;
end loop;
for Iter in 1 .. 1000 loop
for K in reverse Vect'Range loop
declare
Y_K : Integer renames Y (K);
begin
Y_K := Y_K + X (K);
end;
end loop;
end loop;
Text_IO.Put_Line (L_Trim (Integer'Image (Y (1))) &
Integer'Image (Y (N)));
end;
end Ary3;