Path: newsspool2.news.pas.earthlink.net!stamper.news.pas.earthlink.net!elnk-nf2-pas!newsfeed.earthlink.net!wn14feed!wn13feed!wn11feed!worldnet.att.net!199.45.49.37!cyclone1.gnilink.net!spamkiller2.gnilink.net!nwrdny01.gnilink.net.POSTED!53ab2750!not-for-mail Message-ID: <0j27b.3569$ej1.2908@nwrdny01.gnilink.net> From: "Stan Gula" Newsgroups: sci.math Subject: Re: Second Call For Primecounter Contest Entries Date: Mon, 08 Sep 2003 16:41:32 GMT References: Lines: 137 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 151.203.145.16 X-Complaints-To: abuse@verizon.net X-Trace: nwrdny01.gnilink.net 1063039292 151.203.145.16 (Mon, 08 Sep 2003 12:41:32 EDT) NNTP-Posting-Date: Mon, 08 Sep 2003 12:41:32 EDT X-Received-Date: Mon, 08 Sep 2003 09:41:32 PDT (newsspool2.news.pas.earthlink.net) Xref: lexi2.athghost7038suus.net sci.math:36514 "The Ghost In The Machine" wrote in message news:iubu21-0p2.ln1@lexi2.athghost7038suus.net... > In sci.math, Stan Gula > > wrote > on Mon, 08 Sep 2003 07:35:38 GMT > : > > "The Ghost In The Machine" wrote in > > message news:jh1t21-n72.ln1@lexi2.athghost7038suus.net... > >> > >> Sorry, I can't accept your submission at present as all of the values > >> are way off, and I don't see an obvious way of fixing it. Perhaps you > >> can point out the flaw? > > > >> > >> unsigned long long pi(unsigned long long x) > >> { > >> return (unsigned long long) JSHpi2(x, sqrt(x)); > >> } > >> > > > > Problem is right there... Documentation error! > > > > I removed all the usage of sqrt() so the call to JSHpi2 should have the form > > JSHpi2(x,x) - I should have provided a test harness to document that usage. > > > > My harness included stdlib.h which has a template implementation of min() - > > the macro form is fine as stated. > > > > Thanks. > > --Stan Gula > > > > With that fix it works beautifully. Thank you; I can now accept this > submission. :-) Results will shortly be available at > http://home.earthlink.net/~ewill3/math/primecounters/index.html . > > You're between legendrephi and jamesharris3 in the rankings, so far. > One more attempt and I have to retire. I am now showing times as good as Daniel A. Jimenez for tests up to 10^8 and I'm beating him at 10^9. The key was running some tests and watching how the recursion works and caching the first 32 values of pi(x). James' guess that skipping evaluations at even values didn't help and in fact the time to do the test to see if I could skip the evaluations took longer than the amount of time I could save... Note that in his S2 function, the evaluation of sum1 is skipped when sum2==0, and it is obvious that this is so for all even values (except 2). //last submission, Stan Gula mods to the JSH prime counter--- //removed the sqrt calls, and cached the first 32 values of pi(x) #include #include #include unsigned S2(unsigned x, unsigned yin); unsigned JSHpi(unsigned xin, unsigned yin) { //cache most common answers #define cache_size 32 static unsigned f[cache_size]= {0,1,2,2,3,3,4,4,4,4,5,5,6,6,6,6,7,7,8,8,8,8,9,9,9,9,9,9,10,10,11,11}; if(xin==yin && (xin0 on the command line"<