From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,278bf0771374076e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!204.127.204.224.MISMATCH!wns14feed!worldnet.att.net!attbi_s71.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: ada is getting spanked :( References: <1162052997.664967.135910@e3g2000cwe.googlegroups.com> <3321666.DLNnW6yRHq@linux1.krischik.com> <1162085683.30292.23.camel@localhost.localdomain> In-Reply-To: <1162085683.30292.23.camel@localhost.localdomain> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s71 1162088810 12.201.97.213 (Sun, 29 Oct 2006 02:26:50 GMT) NNTP-Posting-Date: Sun, 29 Oct 2006 02:26:50 GMT Date: Sun, 29 Oct 2006 02:26:50 GMT Xref: g2news2.google.com comp.lang.ada:7251 Date: 2006-10-29T02:26:50+00:00 List-Id: 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