From: "Jeffrey R. Carter" <spam.not.jrcarter@acm.not.spam.org>
Subject: Re: ada is getting spanked :(
Date: Sun, 29 Oct 2006 02:26:50 GMT
Date: 2006-10-29T02:26:50+00:00 [thread overview]
Message-ID: <KjU0h.212825$FQ1.169192@attbi_s71> (raw)
In-Reply-To: <1162085683.30292.23.camel@localhost.localdomain>
For the Nsieve problem, is there any reason not to do it like this:
-- The Great Computer Language Shootout
-- http://shootout.alioth.debian.org/
--
-- Contributed by Jim Rogers
-- Modified by Jeffrey R. Carter
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
procedure Count (N : in Natural) is
M : constant Natural := 2 ** N * 10_000;
type Boolean_Array is array (2 .. M) of Boolean;
M2 : constant Natural := M / 2;
M3 : constant Natural := M2 / 2;
C1 : Natural := 0;
C2 : Natural := 0;
C3 : Natural := 0;
S : Boolean_Array := (others => True);
I : Positive;
begin -- Count
for K in S'Range loop
if S (K) then
C1 := C1 + 1;
I := K + K;
if I <= M2 then
C2 := C2 + 1;
if I <= M3 then
C3 := C3 + 1;
end if;
end if;
while I <= M loop
if S (I) then
S (I) := False;
end if;
I := I + K;
end loop;
end if;
end loop;
Put ("Primes up to ");
Put (Item => M, Width => 8);
Put (" ");
Put (Item => C1, Width => 8);
New_Line;
Put ("Primes up to ");
Put (Item => M2, Width => 8);
Put (" ");
Put (Item => C2, Width => 8);
New_Line;
Put ("Primes up to ");
Put (Item => M3, Width => 8);
Put (" ");
Put (Item => C3, Width => 8);
New_Line;
end Count;
N : constant Natural := Natural'Value (Argument (1) );
begin -- Nsieve
Count (N);
end Nsieve;
?
This is much faster (0.6 s on my machine, which gave about 1.8 s for the
existing version), and should put us in 1st place.
--
Jeff Carter
"Your mother was a hamster and your father smelt of elderberries."
Monty Python & the Holy Grail
06
next prev parent reply other threads:[~2006-10-29 2:26 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-28 16:29 ada is getting spanked :( cl1
2006-10-28 17:45 ` Martin Krischik
2006-10-28 20:02 ` Georg Bauhaus
2006-10-29 1:34 ` Georg Bauhaus
2006-10-29 2:13 ` Jeffrey R. Carter
2006-10-29 4:48 ` Isaac Gouy
2006-10-30 1:01 ` Isaac Gouy
2006-10-29 2:26 ` Jeffrey R. Carter [this message]
2006-10-29 2:30 ` Jeffrey R. Carter
2006-10-29 2:33 ` Jeffrey R. Carter
2006-10-29 17:19 ` Jeffrey R. Carter
2006-10-29 17:25 ` Jeffrey R. Carter
2006-10-29 8:54 ` Martin Krischik
2006-10-29 13:01 ` Georg Bauhaus
2006-10-30 0:46 ` Isaac Gouy
2006-10-29 16:27 ` Björn Persson
2006-10-29 20:23 ` Georg Bauhaus
2006-10-29 23:50 ` Björn Persson
2006-10-31 11:32 ` Dmitry A. Kazakov
2006-10-31 13:12 ` Georg Bauhaus
2006-10-31 14:14 ` Dmitry A. Kazakov
2006-10-31 18:01 ` Martin Krischik
2006-10-29 4:58 ` Isaac Gouy
2006-10-29 8:46 ` Martin Krischik
2006-10-30 0:17 ` Isaac Gouy
2006-10-30 18:26 ` jtg
2006-10-30 21:50 ` george
2006-10-31 4:57 ` Jeffrey R. Carter
2006-10-31 6:28 ` Gautier
2006-10-31 6:47 ` Martin Krischik
2006-11-02 18:21 ` Jeffrey R. Carter
2006-11-02 19:37 ` Gautier
2006-11-03 5:11 ` Jeffrey R. Carter
2006-11-03 12:06 ` Martin Krischik
2006-11-03 19:59 ` Jeffrey R. Carter
2006-11-12 22:26 ` Shootout / pidigits [Re: ada is getting spanked :(] Gautier
2006-10-28 22:45 ` ada is getting spanked :( Larry Kilgallen
2006-10-29 16:22 ` Leif Holmgren
2006-10-29 17:28 ` Simon Wright
2006-10-29 19:21 ` jtg
2006-10-29 21:33 ` Leif Holmgren
2006-10-31 11:04 ` Harald Korneliussen
2006-11-01 11:28 ` jtg
2006-11-01 14:31 ` Harald Korneliussen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox