From: Robert Dober Date: 2006-08-02T21:03:26+09:00 Subject: Re: golfing Eratosthenes ------=_Part_69613_25605574.1154520203625 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 8/2/06, Kroeger, Simon (ext) wrote: > > > > > From: Robert Dober [mailto:robert.dober@gmail.com] > > Sent: Wednesday, August 02, 2006 1:26 PM > > > > On 8/2/06, Paul Battley wrote: > > > > > > On 02/08/06, Robert Dober wrote: > > > > Enumerations, all the way ;) > > > > > > > > p (2..100).select{|d|!(2..d-1).find{|c|d%c=3D=3D0}} > > > > > > You can shave a byte off: > > > > > > p (2..100).reject{|d|(2..d-1).find{|c|d%c=3D=3D0}} > > p (2..100).select{|d|(2...d).all?{|c|d%c>0}} > > But it has nothing to do with Eratosthenes anymore... > > cheers > > Simon > > > You are right, too bad, I was having the time of my life ;) But OP's solution does not either, does it? here is the famous sieve from Wikipedia, yes I know, you shall not trust it= , I do not, but as very often this is correct: 1. Write a list of numbers from 2 to the largest number you want to test for primality. Call this List A. 2. Write the number 2, the first prime number, in another list for primes found. Call this List B. 3. Strike off 2 and all multiples of 2 from List A. 4. The first remaining number in the list is a prime number. Write this number into List B. 5. Strike off this number and all multiples of this number from List A. The crossing-off of multiples can be started at the square of the num= ber, as lower multiples have already been crossed out in previous steps. 6. Repeat steps 4 through 6 until no more numbers are left in List A. --=20 Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_69613_25605574.1154520203625--