Question about generators

John Machin sjmachin at lexicon.net
Sun Jul 12 22:26:20 EDT 2009


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.




More information about the Python-list mailing list