[Python-ideas] Is this PEP-able? for X in ListY while conditionZ:
Chris Kaynor
ckaynor at zindagigames.com
Wed Jul 3 01:22:28 CEST 2013
On Tue, Jul 2, 2013 at 3:35 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>wrote:
> Oscar Benjamin wrote:
>
>> def primes():
>> primes_seen = []
>> for n in count(2):
>> if all(n % p for p in primes_seen):
>> yield n
>> primes_seen.append(n)
>>
>> This algorithm is actually even poorer as it doesn't stop at sqrt(n).
>>
>
> Nor should it! When you're only dividing by primes, you
> can't stop at sqrt(n), you have to divide by *all* the
> primes less than n. Otherise you could miss a prime
> factor greater than sqrt(n) whose cofactor is not prime.
>
> (Not relevant to the original disussion, I know, but
> my inner mathematician couldn't restrain himself.)
That would imply that the cofactor has no prime factors (or else you would
have hit them), which would mean it must be prime itself (and therefore you
hit the cofactor earilier).
>
>
> --
> Greg
>
> ______________________________**_________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/**mailman/listinfo/python-ideas<http://mail.python.org/mailman/listinfo/python-ideas>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130702/0a6850e5/attachment.html>
More information about the Python-ideas
mailing list