[Shootout-list] nsieve Ada bench
Pascal Obry
pascal@obry.net
Sat, 19 Mar 2005 13:27:39 +0100
Here is a working version of this bench.
-- $Id$
-- http://dada.perl.it/shootout/
-- Contributed by Pascal Obry on 2005/03/19
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Nsieve is
function Count (M : in Natural) return Natural is
C : Natural := 0;
S : array (2 .. M) of Boolean := (others => True);
I : Positive;
begin
for K in S'Range loop
if S (K) then
C := C + 1;
I := K * 2;
while I <= M loop
S (I) := False;
I := I + K;
end loop;
end if;
end loop;
return C;
end Count;
procedure Run (N : in Natural) is
M : Natural;
begin
M := 2 ** N * 10_000;
Put ("Primes up to ");
Put (Item => M, Width => 8);
Put (Item => Count (M), Width => 8);
New_Line;
end Run;
N : constant Natural := Natural'Value (Argument (1));
begin
Run (N);
Run (N - 1);
Run (N - 2);
end Nsieve;
Pascal.
--
--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595