Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > sci.electronics.design > #408249 > unrolled thread
| Started by | Jamie M <jmorken@shaw.ca> |
|---|---|
| First post | 2016-04-19 14:53 -0700 |
| Last post | 2016-04-21 00:44 -0700 |
| Articles | 20 on this page of 26 — 9 participants |
Back to article view | Back to sci.electronics.design
anyone take a shot at this Jamie M <jmorken@shaw.ca> - 2016-04-19 14:53 -0700
Re: anyone take a shot at this CORRECTED Jamie M <jmorken@shaw.ca> - 2016-04-19 14:58 -0700
Re: anyone take a shot at this DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> - 2016-04-19 22:39 -0400
Re: anyone take a shot at this bitrex <bitrex@de.lete.earthlink.net> - 2016-04-20 14:02 -0400
Re: anyone take a shot at this John S <Sophi.2@invalid.org> - 2016-04-20 13:13 -0500
Re: anyone take a shot at this DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> - 2016-04-20 16:34 -0400
Re: anyone take a shot at this DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> - 2016-04-20 16:31 -0400
Re: anyone take a shot at this bitrex <bitrex@de.lete.earthlink.net> - 2016-04-20 18:32 -0400
Re: anyone take a shot at this DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> - 2016-04-20 20:50 -0400
Re: anyone take a shot at this mrdarrett@gmail.com - 2016-04-20 14:04 -0700
Re: anyone take a shot at this bill.sloman@ieee.org - 2016-04-20 23:36 -0700
Re: anyone take a shot at this mrdarrett@gmail.com - 2016-04-21 11:03 -0700
Re: anyone take a shot at this Jamie M <jmorken@shaw.ca> - 2016-04-21 16:57 -0700
Re: anyone take a shot at this Jasen Betts <jasen@xnet.co.nz> - 2016-04-21 23:50 +0000
Re: anyone take a shot at this mrdarrett@gmail.com - 2016-04-22 15:16 -0700
Re: anyone take a shot at this Jasen Betts <jasen@xnet.co.nz> - 2016-04-23 08:25 +0000
Re: anyone take a shot at this mrdarrett@gmail.com - 2016-04-23 15:36 -0700
Re: anyone take a shot at this Jasen Betts <jasen@xnet.co.nz> - 2016-04-24 01:24 +0000
Re: anyone take a shot at this Bill Sloman <bill.sloman@ieee.org> - 2016-04-24 13:31 +1000
Re: anyone take a shot at this bill.sloman@ieee.org - 2016-04-23 20:35 -0700
Re: anyone take a shot at this mrdarrett@gmail.com - 2016-04-23 21:26 -0700
Re: anyone take a shot at this bill.sloman@ieee.org - 2016-04-24 00:06 -0700
Re: anyone take a shot at this Jasen Betts <jasen@xnet.co.nz> - 2016-04-24 12:05 +0000
Re: anyone take a shot at this bloggs.fredbloggs.fred@gmail.com - 2016-04-20 18:18 -0700
Re: anyone take a shot at this Jamie M <jmorken@shaw.ca> - 2016-04-21 00:35 -0700
Re: anyone take a shot at this bill.sloman@ieee.org - 2016-04-21 00:44 -0700
Page 1 of 2 [1] 2 Next page →
| From | Jamie M <jmorken@shaw.ca> |
|---|---|
| Date | 2016-04-19 14:53 -0700 |
| Subject | anyone take a shot at this |
| Message-ID | <nf69c7$860$1@gioia.aioe.org> |
Hi, In a range of n numbers using a set of π(n)+1 numbers called Y, select the set of numbers Y to maximize the count of pairs of numbers x and y from the set Y where x and y are both prime, and where y is larger than x, and with (y-x) / 2 equal to a number that exists in the set Y. example1: n=1 to 10 π(n)+1 = 5 count of pairs in Y=6 Y=1,2,3,5,7 example2: n=1 to 100 π(n)+1=26 count of pairs in Y=99 Y=1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 cheers, Jamie
[toc] | [next] | [standalone]
| From | Jamie M <jmorken@shaw.ca> |
|---|---|
| Date | 2016-04-19 14:58 -0700 |
| Subject | Re: anyone take a shot at this CORRECTED |
| Message-ID | <nf69md$8f9$1@gioia.aioe.org> |
| In reply to | #408249 |
On 4/19/2016 2:53 PM, Jamie M wrote: > > Hi, > > In a range of n numbers using a set of π(n)+1 numbers called Y, select > the set of numbers Y to maximize the count of pairs of numbers x and y > from the set Y where x and y are both prime, and where y is larger than > x, and with (y-x) / 2 equal to a number that exists in the set Y. > > > example1: > > n=1 to 10 > π(n)+1 = 5 > count of pairs in Y=6 > Y=1,2,3,5,7 > > > > example2: > > n=1 to 100 > π(n)+1=26 > count of pairs in Y=99 > Y=1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 > > > cheers, > Jamie Oops I gotta restate that (there's no requirement that x and y are both prime doh!) This should be hopefully correct: In a range of n numbers using a set of π(n)+1 numbers called Y, select the set of numbers Y to maximize the count of pairs of numbers x and y from the set Y where x and y both exist in Y, and where y is larger than x, and with (y-x) / 2 equal to a number that exists in the set Y. cheers, Jamie
[toc] | [prev] | [next] | [standalone]
| From | DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> |
|---|---|
| Date | 2016-04-19 22:39 -0400 |
| Message-ID | <7uqdhbtvsteih453jb4d1h4in8e8vbgvhg@4ax.com> |
| In reply to | #408249 |
On Tue, 19 Apr 2016 14:53:09 -0700, Jamie M <jmorken@shaw.ca> Gave us: >Hi, Go away,. child
[toc] | [prev] | [next] | [standalone]
| From | bitrex <bitrex@de.lete.earthlink.net> |
|---|---|
| Date | 2016-04-20 14:02 -0400 |
| Message-ID | <VvPRy.81200$_K.74578@fx38.iad> |
| In reply to | #408277 |
DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> Wrote in message: > On Tue, 19 Apr 2016 14:53:09 -0700, Jamie M <jmorken@shaw.ca> Gave us: > >>Hi, > > > Go away,. child > "You took your shot and it did you in! Edison's Medicine! You played your cards but you couldn't win... Edison's Medicine!" -- ----Android NewsGroup Reader---- http://usenet.sinaapp.com/
[toc] | [prev] | [next] | [standalone]
| From | John S <Sophi.2@invalid.org> |
|---|---|
| Date | 2016-04-20 13:13 -0500 |
| Message-ID | <nf8glj$lop$1@dont-email.me> |
| In reply to | #408338 |
On 4/20/2016 1:02 PM, bitrex wrote: > DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> Wrote in > message: >> On Tue, 19 Apr 2016 14:53:09 -0700, Jamie M <jmorken@shaw.ca> Gave us: >> >>> Hi, >> >> >> Go away,. child >> > > "You took your shot and it did you in! > Edison's Medicine! > You played your cards but you couldn't win... > Edison's Medicine!" > I shot an arrow into the air, It fell to earth, I knew not where; For, so swiftly it flew, the sight Could not follow it in its flight. Longfellow
[toc] | [prev] | [next] | [standalone]
| From | DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> |
|---|---|
| Date | 2016-04-20 16:34 -0400 |
| Message-ID | <nqpfhb9u5l65n59hhk96dmke9ss0en75a4@4ax.com> |
| In reply to | #408340 |
On Wed, 20 Apr 2016 13:13:39 -0500, John S <Sophi.2@invalid.org> Gave us: >On 4/20/2016 1:02 PM, bitrex wrote: >> DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> Wrote in >> message: >>> On Tue, 19 Apr 2016 14:53:09 -0700, Jamie M <jmorken@shaw.ca> Gave us: >>> >>>> Hi, >>> >>> >>> Go away,. child >>> >> >> "You took your shot and it did you in! >> Edison's Medicine! >> You played your cards but you couldn't win... >> Edison's Medicine!" >> > >I shot an arrow into the air, >It fell to earth, I knew not where; >For, so swiftly it flew, the sight >Could not follow it in its flight. > >Longfellow Kind of hard to shoot an arrow into the air from a cave hovel in Belize. You two could be a bit more retarded, just not in this life.
[toc] | [prev] | [next] | [standalone]
| From | DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> |
|---|---|
| Date | 2016-04-20 16:31 -0400 |
| Message-ID | <ropfhb9t2d6jtolbgp0s41f6khv7au1fpf@4ax.com> |
| In reply to | #408338 |
On Wed, 20 Apr 2016 14:02:35 -0400 (EDT), bitrex <bitrex@de.lete.earthlink.net> Gave us: >DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> Wrote in > message: >> On Tue, 19 Apr 2016 14:53:09 -0700, Jamie M <jmorken@shaw.ca> Gave us: >> >>>Hi, >> >> >> Go away,. child >> > >"You took your shot and it did you in! >Edison's Medicine! >You played your cards but you couldn't win... >Edison's Medicine!" You're a retard and the shit you spew is more stupid than the lies Donald J. Trump spews.
[toc] | [prev] | [next] | [standalone]
| From | bitrex <bitrex@de.lete.earthlink.net> |
|---|---|
| Date | 2016-04-20 18:32 -0400 |
| Message-ID | <IsTRy.1$FI7.0@fx10.iad> |
| In reply to | #408350 |
DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> Wrote in message: > On Wed, 20 Apr 2016 14:02:35 -0400 (EDT), bitrex > <bitrex@de.lete.earthlink.net> Gave us: > >>DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> Wrote in >> message: >>> On Tue, 19 Apr 2016 14:53:09 -0700, Jamie M <jmorken@shaw.ca> Gave us: >>> >>>>Hi, >>> >>> >>> Go away,. child >>> >> >>"You took your shot and it did you in! >>Edison's Medicine! >>You played your cards but you couldn't win... >>Edison's Medicine!" > > > You're a retard and the shit you spew is more stupid than the lies > Donald J. Trump spews. > Grab a beer with me sometime and I GUARANTEE I will help get you laid. -- ----Android NewsGroup Reader---- http://usenet.sinaapp.com/
[toc] | [prev] | [next] | [standalone]
| From | DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> |
|---|---|
| Date | 2016-04-20 20:50 -0400 |
| Message-ID | <2t8ghbhcijj688db9ubv9m41e83gjrk6sd@4ax.com> |
| In reply to | #408356 |
On Wed, 20 Apr 2016 18:32:13 -0400 (EDT), bitrex <bitrex@de.lete.earthlink.net> Gave us: >DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> Wrote in > message: >> On Wed, 20 Apr 2016 14:02:35 -0400 (EDT), bitrex >> <bitrex@de.lete.earthlink.net> Gave us: >> >>>DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> Wrote in >>> message: >>>> On Tue, 19 Apr 2016 14:53:09 -0700, Jamie M <jmorken@shaw.ca> Gave us: >>>> >>>>>Hi, >>>> >>>> >>>> Go away,. child >>>> >>> >>>"You took your shot and it did you in! >>>Edison's Medicine! >>>You played your cards but you couldn't win... >>>Edison's Medicine!" >> >> >> You're a retard and the shit you spew is more stupid than the lies >> Donald J. Trump spews. >> > >Grab a beer with me sometime and I GUARANTEE I will help get you laid. Fuck you. You are not worthy of my beer grabbing company, much less my chick charming prowess.
[toc] | [prev] | [next] | [standalone]
| From | mrdarrett@gmail.com |
|---|---|
| Date | 2016-04-20 14:04 -0700 |
| Message-ID | <67fb3d1b-2b65-4532-bea3-bdd282dc8f66@googlegroups.com> |
| In reply to | #408249 |
On Tuesday, April 19, 2016 at 2:53:19 PM UTC-7, Jamie M wrote: > Hi, > > In a range of n numbers using a set of π(n)+1 numbers called Y, select > the set of numbers Y to maximize the count of pairs of numbers x and y > from the set Y where x and y are both prime, and where y is larger than > x, and with (y-x) / 2 equal to a number that exists in the set Y. > > > example1: > > n=1 to 10 > π(n)+1 = 5 > count of pairs in Y=6 > Y=1,2,3,5,7 > > > > example2: > > n=1 to 100 > π(n)+1=26 > count of pairs in Y=99 > Y=1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 > > > cheers, > Jamie It appears that sci.math would be a better forum for this. https://groups.google.com/forum/#!forum/sci.math Good luck! Michael
[toc] | [prev] | [next] | [standalone]
| From | bill.sloman@ieee.org |
|---|---|
| Date | 2016-04-20 23:36 -0700 |
| Message-ID | <4c828146-2448-4d29-8097-f01ab6577285@googlegroups.com> |
| In reply to | #408352 |
On Thursday, April 21, 2016 at 7:04:48 AM UTC+10, mrda...@gmail.com wrote: > On Tuesday, April 19, 2016 at 2:53:19 PM UTC-7, Jamie M wrote: > > Hi, > > > > In a range of n numbers using a set of π(n)+1 numbers called Y, select > > the set of numbers Y to maximize the count of pairs of numbers x and y > > from the set Y where x and y are both prime, and where y is larger than > > x, and with (y-x) / 2 equal to a number that exists in the set Y. > > > > > > example1: > > > > n=1 to 10 > > π(n)+1 = 5 > > count of pairs in Y=6 > > Y=1,2,3,5,7 > > > > > > > > example2: > > > > n=1 to 100 > > π(n)+1=26 > > count of pairs in Y=99 > > Y=1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 > > > > > > cheers, > > Jamie > > > It appears that sci.math would be a better forum for this. > > https://groups.google.com/forum/#!forum/sci.math > > Good luck! He'd need it - on present evidence what he actually needs is sci.remedial.math In fact he's explicitly rejected posting anywhere where anybody might be interested in what he posts - he wants to work it out for himself, which would probably need a brain transplant, or at least an implant, granting that nature seems to have drastically short-changed him in that department. -- Bill Sloman, Sydney
[toc] | [prev] | [next] | [standalone]
| From | mrdarrett@gmail.com |
|---|---|
| Date | 2016-04-21 11:03 -0700 |
| Message-ID | <bfcaefd1-c7d6-4889-b12f-0c2408ef373e@googlegroups.com> |
| In reply to | #408407 |
On Wednesday, April 20, 2016 at 11:36:41 PM UTC-7, bill....@ieee.org wrote: > On Thursday, April 21, 2016 at 7:04:48 AM UTC+10, mrda...@gmail.com wrote: > > On Tuesday, April 19, 2016 at 2:53:19 PM UTC-7, Jamie M wrote: > > > Hi, > > > > > > In a range of n numbers using a set of π(n)+1 numbers called Y, select > > > the set of numbers Y to maximize the count of pairs of numbers x and y > > > from the set Y where x and y are both prime, and where y is larger than > > > x, and with (y-x) / 2 equal to a number that exists in the set Y. > > > > > > > > > example1: > > > > > > n=1 to 10 > > > π(n)+1 = 5 > > > count of pairs in Y=6 > > > Y=1,2,3,5,7 > > > > > > > > > > > > example2: > > > > > > n=1 to 100 > > > π(n)+1=26 > > > count of pairs in Y=99 > > > Y=1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 > > > > > > > > > cheers, > > > Jamie > > > > > > It appears that sci.math would be a better forum for this. > > > > https://groups.google.com/forum/#!forum/sci.math > > > > Good luck! > > He'd need it - on present evidence what he actually needs is sci.remedial.math > > In fact he's explicitly rejected posting anywhere where anybody might be interested in what he posts - he wants to work it out for himself, which would probably need a brain transplant, or at least an implant, granting that nature seems to have drastically short-changed him in that department. > > -- > Bill Sloman, Sydney Oh, I don't know. His post inspired me to look at the Sieve of Eratosthenes. Quite fun. There's a sample sieve code with the FreeBasic compiler. After some modification (it only finds the first million primes) it took my computer just 7.5 seconds to find the first 25 million primes. I'd forgotten how much fun such things could be. Of course, to find these primes, about 2 gigabytes of RAM for array space are needed... I'm sure the algorithm could be refined further by avoiding storage of multiples of two... Carry on! Michael
[toc] | [prev] | [next] | [standalone]
| From | Jamie M <jmorken@shaw.ca> |
|---|---|
| Date | 2016-04-21 16:57 -0700 |
| Message-ID | <nfbpde$nee$1@gioia.aioe.org> |
| In reply to | #408458 |
On 4/21/2016 11:03 AM, mrdarrett@gmail.com wrote: > On Wednesday, April 20, 2016 at 11:36:41 PM UTC-7, bill....@ieee.org wrote: >> On Thursday, April 21, 2016 at 7:04:48 AM UTC+10, mrda...@gmail.com wrote: >>> On Tuesday, April 19, 2016 at 2:53:19 PM UTC-7, Jamie M wrote: >>>> Hi, >>>> >>>> In a range of n numbers using a set of π(n)+1 numbers called Y, select >>>> the set of numbers Y to maximize the count of pairs of numbers x and y >>>> from the set Y where x and y are both prime, and where y is larger than >>>> x, and with (y-x) / 2 equal to a number that exists in the set Y. >>>> >>>> >>>> example1: >>>> >>>> n=1 to 10 >>>> π(n)+1 = 5 >>>> count of pairs in Y=6 >>>> Y=1,2,3,5,7 >>>> >>>> >>>> >>>> example2: >>>> >>>> n=1 to 100 >>>> π(n)+1=26 >>>> count of pairs in Y=99 >>>> Y=1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 >>>> >>>> >>>> cheers, >>>> Jamie >>> >>> >>> It appears that sci.math would be a better forum for this. >>> >>> https://groups.google.com/forum/#!forum/sci.math >>> >>> Good luck! >> >> He'd need it - on present evidence what he actually needs is sci.remedial.math >> >> In fact he's explicitly rejected posting anywhere where anybody might be interested in what he posts - he wants to work it out for himself, which would probably need a brain transplant, or at least an implant, granting that nature seems to have drastically short-changed him in that department. >> >> -- >> Bill Sloman, Sydney > > > Oh, I don't know. His post inspired me to look at the Sieve of Eratosthenes. Quite fun. There's a sample sieve code with the FreeBasic compiler. After some modification (it only finds the first million primes) it took my computer just 7.5 seconds to find the first 25 million primes. I'd forgotten how much fun such things could be. Of course, to find these primes, about 2 gigabytes of RAM for array space are needed... I'm sure the algorithm could be refined further by avoiding storage of multiples of two... > > Carry on! > > Michael Haha thanks for the encouragement. Glad to hear you are having fun too, thats great, something mysterious about the primes seems to make it fun :) I want to get back to sieve stuff at some point soon too, seems like the best way to get a handle on the primes. cheers, Jamie >
[toc] | [prev] | [next] | [standalone]
| From | Jasen Betts <jasen@xnet.co.nz> |
|---|---|
| Date | 2016-04-21 23:50 +0000 |
| Message-ID | <nfbp12$b0q$1@gonzo.alcatraz> |
| In reply to | #408458 |
> > Oh, I don't know. His post inspired me to look at the Sieve of Eratosthenes. Quite fun. There's a sample sieve code with the FreeBasic compiler. After some modification (it only finds the first million primes) it took my computer just 7.5 seconds to find the first 25 million primes. I'd forgotten how much fun such things could be. Of course, to find these primes, about 2 gigabytes of RAM for array space are needed... I'm sure the algorithm could be refined further by avoiding storage of multiples of two... sounds pretty crap if it runs out of memorty like that. I was able to avoid that problem in 1998 (found 200 million primes used less than 128K memory) -- \_(ツ)_
[toc] | [prev] | [next] | [standalone]
| From | mrdarrett@gmail.com |
|---|---|
| Date | 2016-04-22 15:16 -0700 |
| Message-ID | <9023ec34-fa71-498d-9254-69ca2ff88e42@googlegroups.com> |
| In reply to | #408523 |
On Thursday, April 21, 2016 at 5:31:42 PM UTC-7, Jasen Betts wrote:
> >
> > Oh, I don't know. His post inspired me to look at the Sieve of
> Eratosthenes. Quite fun. There's a sample sieve code with the
> FreeBasic compiler. After some modification (it only finds the first
> million primes) it took my computer just 7.5 seconds to find the first
> 25 million primes. I'd forgotten how much fun such things could be.
> Of course, to find these primes, about 2 gigabytes of RAM for array
> space are needed... I'm sure the algorithm could be refined further by
> avoiding storage of multiples of two...
>
> sounds pretty crap if it runs out of memorty like that.
> I was able to avoid that problem in 1998 (found 200 million primes
> used less than 128K memory)
>
> --
> \_(ツ)_
Which algorithm did you use, and how long did it take?
Eratosthenes is supposed to be fast, something like log log N.
I suppose I could use this N^2 algorithm, which only uses a few bytes of memory for variables :p
for( i=2; i<MAX_PRIME; i++ ){
isPrime=1;
for( j=i-1; j>=2; j-- )
if( (i % j) == 0 )
isPrime = 0;
if( isPrime == 1 )
printf( "%d ", i );
}
Michael
[toc] | [prev] | [next] | [standalone]
| From | Jasen Betts <jasen@xnet.co.nz> |
|---|---|
| Date | 2016-04-23 08:25 +0000 |
| Message-ID | <nffbhc$roa$1@gonzo.alcatraz> |
| In reply to | #408683 |
On 2016-04-22, mrdarrett@gmail.com <mrdarrett@gmail.com> wrote:
> On Thursday, April 21, 2016 at 5:31:42 PM UTC-7, Jasen Betts wrote:
>> >
>> > Oh, I don't know. His post inspired me to look at the Sieve of
>> Eratosthenes. Quite fun. There's a sample sieve code with the
>> FreeBasic compiler. After some modification (it only finds the first
>> million primes) it took my computer just 7.5 seconds to find the first
>> 25 million primes. I'd forgotten how much fun such things could be.
>> Of course, to find these primes, about 2 gigabytes of RAM for array
>> space are needed... I'm sure the algorithm could be refined further by
>> avoiding storage of multiples of two...
>>
>> sounds pretty crap if it runs out of memorty like that.
>> I was able to avoid that problem in 1998 (found 200 million primes
>> used less than 128K memory)
>>
>> --
>> \_(ツ)_
>
>
> Which algorithm did you use
piecewise seive.
basically the same algorithm, but recycling the seive memory.
> and how long did it take?
"all night" on a 486sx 33Mhz running DOS
> Eratosthenes is supposed to be fast, something like log log N.
AFAIK it's the fastest way to find all primes.
https://fidonet.ozzmosis.com/echomail.php/c_echo/8333893e42ae1d27.html
I think that syntax error is noise (delete that line)
It doesn't run right on 64 bit systems, I think because it makes unwise
assumptions on the magnitude if ULONG_MAX.
compiled for 64 bit linux it took about 37 seconds to search to 2^32
on my work PC then failed to stop and eventually died with segv, my
laptop is a bit slower. it took 4 minutes.
in 1998 it would have been faster to read 200 million primes from a
CD-rom
attached is a slightly updated version, I haven't tested it past 2^32
/*_|_| erastothenes.c
_|_|_| A program to find all the primes <= MAX_ULONG
_|_|_| No warrantee or guarantee implied.
_|_|_| Released PUBLIC DOMAIN by Jasen Betts. (11/Aug/98)*/
/* updated for more modren systems 2016 */
/* here's a piecewise implememtation of erastothenes' sieve for
* finding prime numbers, it should be able to go all the way
* to MAX_ULONG, (see <limits.h>).
* because it takes some time to run it prints a status line
* (to stderr) every 1000 primes, this behavior can be modified
* by defining STATUS_FREQ to another number, 0 disables it
*
* SIEVESIZE determines the size of the char-array used to do the sieveing
* factors of (MAX_ULONG+1) should be used (they are all powers of 2)
* 32768u is the biggest my 16-bit compiler allows.
*/
#include <stdio.h>
#include <math.h> /* only used for sqrt() */
#include <time.h>
#include <stdlib.h>
#define SIEVESIZE (32768u) /* must be a power of 2 */
#define SIEVEMAX (SIEVESIZE-1)
#ifndef STATUS_FREQ
#define STATUS_FREQ (1000000)
#endif
/*when to stop (should be a multiple of seivesize
* else it will overshoot a little)
*/
#define MAXPRIME (0x100000000ll)
/* tablesize should be more than the number of
* primes under sqrt(MAXPRIME)
* 7000 is enough to compute upto 2^32
* if you set it too low you will
* get undefined behaviour.
* To go to 2^64 use 204000000 here
*/
#define TABLESIZE 7000
char sieve[SIEVESIZE];
unsigned long x,y,z,count=1,max,base=0,roof;
unsigned long t;
unsigned i,j;
int print,hits=STATUS_FREQ-1;
int main(int argc,char**argv){
unsigned long *primes,*tuples;
primes=calloc(sizeof(long),TABLESIZE);
if (NULL==primes){puts("MALLOC ERROR-1");abort();}
tuples=calloc(sizeof(long),TABLESIZE);
if (NULL==tuples){puts("MALLOC ERROR-2");abort();}
primes[0]=2;tuples[0]=4;
primes[1]=3;tuples[1]=9;
print=(argc > 1);
for(i=0;i<SIEVEMAX;) {sieve[i++]=0;sieve[i++]=1;}
max = (int) sqrt(SIEVEMAX)+1;
for(i=3; primes[(int)count-1]<=max;i++)
if(sieve[i]){
primes[(int)count]=i+base;
j=(int)(tuples[(int)count]=(base+i)*(i+base));
while(j<max)
{
sieve[j-(int)base]=0;
j+=(int)primes[(int)count]*2;
}
++count;
}
count=-1;
base=0;
do
{
roof=base+SIEVESIZE;
max = (long)floor(sqrt(roof-1)+1) ;
// if(roof>100000) #roof-=65536;
for(i=0;i<SIEVESIZE;) {sieve[i++]=0;sieve[i++]=1;}
for(i=1;(x=primes[i])<=max;++i)
{
y=tuples[i];
x<<=1;
while((long)(roof-y) >0) /* coded like that to foil integer overflow */
{
sieve[(int)(y-base)]=0;
y+=x;
}
tuples[i]=y;
}
for(i=0;i<SIEVESIZE;i++)
if(sieve[i]){
if((i+base)==1l)i++;
if (print) printf("%6ld\n",i+base);
if (++count<7000)
{
primes[(int)(count)]=i+base;
if(!tuples[(int)count]) tuples[(int)count]=(base+i)*(i+base);
}
#if STATUS_FREQ
if(!--hits)
{
fprintf(stderr,"\rcount: %12ld / prime: %13lu time: %8.1f"
,count+2, i+base, (double)clock()/CLOCKS_PER_SEC);
hits=STATUS_FREQ;
}
#endif
}
base +=SIEVESIZE;
}
while( base && base < MAXPRIME );
printf("\n%lu primes %.1f seconds\n",count+2,(double)clock()/CLOCKS_PER_SEC);
return 0;
}
--
\_(ツ)_
[toc] | [prev] | [next] | [standalone]
| From | mrdarrett@gmail.com |
|---|---|
| Date | 2016-04-23 15:36 -0700 |
| Message-ID | <4e4f2953-6969-43c0-8439-49a45474b9ea@googlegroups.com> |
| In reply to | #408742 |
On Saturday, April 23, 2016 at 1:31:26 AM UTC-7, Jasen Betts wrote:
> On 2016-04-22, mrdarrett@gmail.com <mrdarrett@gmail.com> wrote:
> > On Thursday, April 21, 2016 at 5:31:42 PM UTC-7, Jasen Betts wrote:
> >> >
> >> > Oh, I don't know. His post inspired me to look at the Sieve of
> >> Eratosthenes. Quite fun. There's a sample sieve code with the
> >> FreeBasic compiler. After some modification (it only finds the first
> >> million primes) it took my computer just 7.5 seconds to find the first
> >> 25 million primes. I'd forgotten how much fun such things could be.
> >> Of course, to find these primes, about 2 gigabytes of RAM for array
> >> space are needed... I'm sure the algorithm could be refined further by
> >> avoiding storage of multiples of two...
> >>
> >> sounds pretty crap if it runs out of memorty like that.
> >> I was able to avoid that problem in 1998 (found 200 million primes
> >> used less than 128K memory)
> >>
> >> --
> >> \_(ツ)_
> >
> >
> > Which algorithm did you use
>
> piecewise seive.
> basically the same algorithm, but recycling the seive memory.
>
> > and how long did it take?
>
> "all night" on a 486sx 33Mhz running DOS
>
> > Eratosthenes is supposed to be fast, something like log log N.
>
> AFAIK it's the fastest way to find all primes.
>
>
>
> https://fidonet.ozzmosis.com/echomail.php/c_echo/8333893e42ae1d27.html
>
>
> I think that syntax error is noise (delete that line)
>
> It doesn't run right on 64 bit systems, I think because it makes unwise
> assumptions on the magnitude if ULONG_MAX.
>
> compiled for 64 bit linux it took about 37 seconds to search to 2^32
> on my work PC then failed to stop and eventually died with segv, my
> laptop is a bit slower. it took 4 minutes.
>
> in 1998 it would have been faster to read 200 million primes from a
> CD-rom
>
> attached is a slightly updated version, I haven't tested it past 2^32
>
> /*_|_| erastothenes.c
> _|_|_| A program to find all the primes <= MAX_ULONG
> _|_|_| No warrantee or guarantee implied.
> _|_|_| Released PUBLIC DOMAIN by Jasen Betts. (11/Aug/98)*/
> /* updated for more modren systems 2016 */
>
> /* here's a piecewise implememtation of erastothenes' sieve for
> * finding prime numbers, it should be able to go all the way
> * to MAX_ULONG, (see <limits.h>).
> * because it takes some time to run it prints a status line
> * (to stderr) every 1000 primes, this behavior can be modified
> * by defining STATUS_FREQ to another number, 0 disables it
> *
> * SIEVESIZE determines the size of the char-array used to do the sieveing
> * factors of (MAX_ULONG+1) should be used (they are all powers of 2)
> * 32768u is the biggest my 16-bit compiler allows.
> */
>
> #include <stdio.h>
> #include <math.h> /* only used for sqrt() */
> #include <time.h>
> #include <stdlib.h>
>
> #define SIEVESIZE (32768u) /* must be a power of 2 */
> #define SIEVEMAX (SIEVESIZE-1)
> #ifndef STATUS_FREQ
> #define STATUS_FREQ (1000000)
> #endif
>
> /*when to stop (should be a multiple of seivesize
> * else it will overshoot a little)
> */
>
> #define MAXPRIME (0x100000000ll)
>
> /* tablesize should be more than the number of
> * primes under sqrt(MAXPRIME)
> * 7000 is enough to compute upto 2^32
> * if you set it too low you will
> * get undefined behaviour.
> * To go to 2^64 use 204000000 here
> */
>
> #define TABLESIZE 7000
>
>
> char sieve[SIEVESIZE];
> unsigned long x,y,z,count=1,max,base=0,roof;
> unsigned long t;
> unsigned i,j;
> int print,hits=STATUS_FREQ-1;
> int main(int argc,char**argv){
> unsigned long *primes,*tuples;
> primes=calloc(sizeof(long),TABLESIZE);
> if (NULL==primes){puts("MALLOC ERROR-1");abort();}
> tuples=calloc(sizeof(long),TABLESIZE);
> if (NULL==tuples){puts("MALLOC ERROR-2");abort();}
> primes[0]=2;tuples[0]=4;
> primes[1]=3;tuples[1]=9;
> print=(argc > 1);
>
> for(i=0;i<SIEVEMAX;) {sieve[i++]=0;sieve[i++]=1;}
> max = (int) sqrt(SIEVEMAX)+1;
> for(i=3; primes[(int)count-1]<=max;i++)
> if(sieve[i]){
> primes[(int)count]=i+base;
> j=(int)(tuples[(int)count]=(base+i)*(i+base));
>
> while(j<max)
> {
> sieve[j-(int)base]=0;
> j+=(int)primes[(int)count]*2;
> }
> ++count;
> }
> count=-1;
> base=0;
> do
> {
> roof=base+SIEVESIZE;
> max = (long)floor(sqrt(roof-1)+1) ;
> // if(roof>100000) #roof-=65536;
> for(i=0;i<SIEVESIZE;) {sieve[i++]=0;sieve[i++]=1;}
> for(i=1;(x=primes[i])<=max;++i)
> {
> y=tuples[i];
> x<<=1;
> while((long)(roof-y) >0) /* coded like that to foil integer overflow */
> {
> sieve[(int)(y-base)]=0;
> y+=x;
> }
> tuples[i]=y;
> }
> for(i=0;i<SIEVESIZE;i++)
> if(sieve[i]){
> if((i+base)==1l)i++;
> if (print) printf("%6ld\n",i+base);
> if (++count<7000)
> {
> primes[(int)(count)]=i+base;
> if(!tuples[(int)count]) tuples[(int)count]=(base+i)*(i+base);
> }
> #if STATUS_FREQ
> if(!--hits)
> {
> fprintf(stderr,"\rcount: %12ld / prime: %13lu time: %8.1f"
> ,count+2, i+base, (double)clock()/CLOCKS_PER_SEC);
> hits=STATUS_FREQ;
> }
> #endif
> }
> base +=SIEVESIZE;
> }
> while( base && base < MAXPRIME );
> printf("\n%lu primes %.1f seconds\n",count+2,(double)clock()/CLOCKS_PER_SEC);
> return 0;
> }
>
>
> --
> \_(ツ)_
Wow! Thank you for posting this. I will have to study this further.
Much appreciated!
Michael
[toc] | [prev] | [next] | [standalone]
| From | Jasen Betts <jasen@xnet.co.nz> |
|---|---|
| Date | 2016-04-24 01:24 +0000 |
| Message-ID | <nfh794$93o$1@gonzo.alcatraz> |
| In reply to | #408834 |
On 2016-04-23, mrdarrett@gmail.com <mrdarrett@gmail.com> wrote: > On Saturday, April 23, 2016 at 1:31:26 AM UTC-7, Jasen Betts wrote: >> /*_|_| erastothenes.c >> _|_|_| A program to find all the primes <= MAX_ULONG >> _|_|_| No warrantee or guarantee implied. >> _|_|_| Released PUBLIC DOMAIN by Jasen Betts. (11/Aug/98)*/ >> /* updated for more modren systems 2016 */ > Wow! Thank you for posting this. I will have to study this further. No prob. sorry about the lack of comments, I think the first loop collects the primes out to 0x10000 and then the second pair of loops uses those to compute the primes out to 0x100000000 it doesn't do anything with the primes it finds, other than count them. -- \_(ツ)_
[toc] | [prev] | [next] | [standalone]
| From | Bill Sloman <bill.sloman@ieee.org> |
|---|---|
| Date | 2016-04-24 13:31 +1000 |
| Message-ID | <nfhefj$krb$1@dont-email.me> |
| In reply to | #408458 |
On 22/04/2016 4:03 AM, mrdarrett@gmail.com wrote: > On Wednesday, April 20, 2016 at 11:36:41 PM UTC-7, bill....@ieee.org wrote: >> On Thursday, April 21, 2016 at 7:04:48 AM UTC+10, mrda...@gmail.com wrote: >>> On Tuesday, April 19, 2016 at 2:53:19 PM UTC-7, Jamie M wrote: <snip> >>> Good luck! >> >> He'd need it - on present evidence what he actually needs is sci.remedial.math >> >> In fact he's explicitly rejected posting anywhere where anybody might be interested in what he posts - he wants to work it out for himself, which would probably need a brain transplant, or at least an implant, granting that nature seems to have drastically short-changed him in that department. > > Oh, I don't know. His post inspired me to look at the Sieve of Eratosthenes. Quite fun. There's a sample sieve code with the FreeBasic compiler. After some modification (it only finds the first million primes) it took my computer just 7.5 seconds to find the first 25 million primes. I'd forgotten how much fun such things could be. Of course, to find these primes, about 2 gigabytes of RAM for array space are needed... I'm sure the algorithm could be refined further by avoiding storage of multiples of two... > > Carry on! I've known about the Sieve of Eratosthenes for many years now. In fact I was inspired to try to work out a probablistic estimator of it's success a couple of months ago. The simplest predictor is that the chance of an individual application of the sieve will find a non-prime in a collection of n numbers is 1/(1-1/p) where p is the prime being tested for. This doesn't work, because the population of numbers being sieved is progressively depleted of smaller primes as the test progresses. To improve it, you have to know (or guess) the number of primes - p_a - below the first number in the sample being tested - think Legendre Conjecture - and guess the number of primes in the sample being tested p_b. As you work your way through p(a) the chance of finding a number divisible by a known prime goes up at the "k"th step by (p_a + p_b)/(p_a + p_b - k) It seemed to work fairly well when I tried it out in Excel, but I couldn't be bothered getting into my Linux partition and testing it in a respectable programming language over a respectable number of samples. It generated a slightly conservative estimate for p_b when I tried it, but I'd need to run a lot more trials to say anything persuasive. -- Bill Sloman, Sydney
[toc] | [prev] | [next] | [standalone]
| From | bill.sloman@ieee.org |
|---|---|
| Date | 2016-04-23 20:35 -0700 |
| Message-ID | <c4926c54-1ba1-4d7b-ab50-fdcb28746688@googlegroups.com> |
| In reply to | #408876 |
On Sunday, April 24, 2016 at 1:31:18 PM UTC+10, Bill Sloman wrote: > On 22/04/2016 4:03 AM, mrdarrett@gmail.com wrote: > > On Wednesday, April 20, 2016 at 11:36:41 PM UTC-7, bill....@ieee.org wrote: > >> On Thursday, April 21, 2016 at 7:04:48 AM UTC+10, mrda...@gmail.com wrote: > >>> On Tuesday, April 19, 2016 at 2:53:19 PM UTC-7, Jamie M wrote: > > <snip> > > >>> Good luck! > >> > >> He'd need it - on present evidence what he actually needs is sci.remedial.math > >> > >> In fact he's explicitly rejected posting anywhere where anybody might be interested in what he posts - he wants to work it out for himself, which would probably need a brain transplant, or at least an implant, granting that nature seems to have drastically short-changed him in that department. > > > > Oh, I don't know. His post inspired me to look at the Sieve of Eratosthenes. Quite fun. There's a sample sieve code with the FreeBasic compiler. After some modification (it only finds the first million primes) it took my computer just 7.5 seconds to find the first 25 million primes. I'd forgotten how much fun such things could be. Of course, to find these primes, about 2 gigabytes of RAM for array space are needed... I'm sure the algorithm could be refined further by avoiding storage of multiples of two... > > > > Carry on! > > I've known about the Sieve of Eratosthenes for many years now. In fact I > was inspired to try to work out a probablistic estimator of it's success > a couple of months ago. > > The simplest predictor is that the chance of an individual application > of the sieve will find a non-prime in a collection of n numbers is > > 1/(1-1/p) where p is the prime being tested for. Oops. That obviously should be 1/p. The population you have left goes down by the factor 1/(1-1/p). > This doesn't work, because the population of numbers being sieved is > progressively depleted of smaller primes as the test progresses. To > improve it, you have to know (or guess) the number of primes - p_a - > below the first number in the sample being tested - think Legendre > Conjecture - and guess the number of primes in the sample being tested p_b. > > As you work your way through p(a) the chance of finding a number > divisible by a known prime goes up at the "k"th step by > > (p_a + p_b)/(p_a + p_b - k) > > It seemed to work fairly well when I tried it out in Excel, but I > couldn't be bothered getting into my Linux partition and testing it in a > respectable programming language over a respectable number of samples. > > It generated a slightly conservative estimate for p_b when I tried it, > but I'd need to run a lot more trials to say anything persuasive. > > -- > Bill Sloman, Sydney
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | sci.electronics.design
csiph-web