Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #50382

Re: Prime number generator

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.049
X-Spam-Evidence '*H*': 0.93; '*S*': 0.02; 'root': 0.05; 'noted,': 0.09; 'subject:number': 0.09; 'runs': 0.10; 'python': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:Prime': 0.16; 'subject:generator': 0.16; 'tweak': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'algorithms.': 0.24; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'converting': 0.30; 'message- id:@mail.gmail.com': 0.30; 'received:google.com': 0.35; 'done': 0.36; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'ian': 0.60; 'jul': 0.74; 'prime': 0.74; 'square': 0.74; 'comparable': 0.84; 'excessive': 0.84; 'tossing': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Ctcqki5T0NuAdFX77nZqq6nNWKLCpUcno1VV63rKFTo=; b=vxg6OGGhT1PdQZcv6q6Gsl8KGW+RZNv1jnlMNy3hIHqfXaglCbhQ2FXBk071p4uYUc /cXSoaWrQjaJUdSN6g7Ufx2usWD4xDpreJBPsLqvfCaIVHQhfznR1IxJZdP8dEDJ5IzC nfnC9mSHef5W3WbHBxPjBJmhDjURYDvislhro8J3N3QYeb4fGejsCu/Q6kmUaD/imABC EE2yb5Xh5WqZFwfDgDD48lBsHNyznB02Bs6oVd88TxOUopnvjfLEpNQ2WbaWz1W6laPE xSQ9kQketYuZE1+XnvzYzjughs1xXMt/tSKXWKZy/wUSeaCju6cmi9Tvf1NnIIeOIe+Y M5oQ==
MIME-Version 1.0
X-Received by 10.221.4.4 with SMTP id oa4mr4826984vcb.70.1373476470740; Wed, 10 Jul 2013 10:14:30 -0700 (PDT)
In-Reply-To <CALwzidmkf6WOGkMWPJ8we+pA6RTkvJK+0ZRi0DJ0DUt245rruQ@mail.gmail.com>
References <CAPTjJmq_7+rtNV22cxpLXQ+G1XfCyJvKckN+2B3PjfVEEs-5Qw@mail.gmail.com> <CALwzidmy-CZYOZ2hdcssOWOZ+U8GVv8MrcjG0LD6TtwbdhBX6w@mail.gmail.com> <CALwzidmkf6WOGkMWPJ8we+pA6RTkvJK+0ZRi0DJ0DUt245rruQ@mail.gmail.com>
Date Thu, 11 Jul 2013 03:14:30 +1000
Subject Re: Prime number generator
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4540.1373476473.3114.python-list@python.org> (permalink)
Lines 14
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1373476473 news.xs4all.nl 15994 [2001:888:2000:d::a6]:49212
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:50382

Show key headers only | View raw


On Thu, Jul 11, 2013 at 2:54 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> As promised.  Apologies for the excessive commenting.  As noted, this
> implementation is a recursive generator, which is done so that the
> primes in the sieve can go only up to the square root of the current
> prime, rather than tossing in every prime seen so far.
>


Nice. Comes in at 0.23369310904039478 in my oh-so-scientific
benchmarking, so it's comparable to several of Steven's algorithms.
Runs on Python 3.3 with just the tiny tweak of converting iter.next()
to next(iter).

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Prime number generator Chris Angelico <rosuav@gmail.com> - 2013-07-11 03:14 +1000

csiph-web