Question about generators

Cameron Pulsford cameron.pulsford at gmail.com
Sun Jul 12 23:17:31 EDT 2009


I read it on the haskell site in their sieves/prime wheel section, I  
guess I misunderstood something. (east to do over there...) I did  
verify it against established list of primes and other generators I've  
written that use more normal methods, but I only hand verified it.

It is at least interesting though, I can probably extend it to check  
for primality by using a more normal sieve method. It might be pretty  
fast too because generally it does only generate primes, and the few  
non primes it does generate could be caught quickly using a scratching  
out technique.

When I was initially looking at it there are some interesting patterns  
I might be able to extend into a generator that would yield only  
correct sets of numbers for the 6x + n pattern.


On Jul 12, 2009, at 10:26 PM, John Machin wrote:

> On Jul 13, 11:24 am, Cameron Pulsford <cameron.pulsf... at gmail.com>
> wrote:
>
>> As far as the primes generator, it does not generate any non-primes.
>> All primes (except 2, 3 and 5) are in the form (6*x + 1, 6*x + 5)
>> where is x is [1, 2, ..., n]. The only time it doesn't generate a
>> prime is when x + (1 or 5) % 5 == 0. Which is what that last part is
>> making sure doesn't happen. I'm not a mathematician or anything so
>> correct me if I'm wrong, but that's what I've read.
>
> Where did you read that? Have you tried to verify it, like this:
>
> | >>> [6*i+j for i in range(1, 21) for j in (1, 5) if (i+j) % 5]
> | [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 49, 53, 59, 61, 67,
> 71, 73, 77, 79, 83, 89, 91, 97, 101, 103, 107, 109, 113, 119, 121]
>
> 49, 77, 91, and 121 are not prime.
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list