Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.021 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'algorithm': 0.04; 'modified': 0.07; 'odd': 0.07; 'remaining': 0.07; 'indeed,': 0.09; '2),': 0.16; 'determining': 0.16; 'limit,': 0.16; 'multiplies': 0.16; 'wrote:': 0.18; 'pointed': 0.19; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'url:wiki': 0.31; 'sep': 0.31; 'url:wikipedia': 0.31; 'run': 0.32; 'fri,': 0.33; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'done,': 0.36; 'url:org': 0.36; 'example,': 0.37; 'list': 0.37; 'step': 0.37; 'to:addr:python-list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'numbers': 0.61; 'prime': 0.74; 'divide': 0.84; 'high,': 0.84; 'indefinitely': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=xoVOhjWwNjHILulnV6gv6m2qjLcAeXAea/vT+xvJQdM=; b=u+Wf6zWtbZ0vAGAeh6IgfdU7eBV0giuMDQzEAO5GebPPOs/lmbRusKodl5iimNvcYt xuTmzdmwIh4Tv4MkE9ObDJepo5Hc0myvFDREa3v7bparPdmJLtDIpr0DwGahMC39FuJC +wbGj+Gbo1+++VDYnpJJEskwZuqf1QgW2YBx1+Ww+Bi4Os4z4ZSY3RyLF1asdZ2MxH8P sAi888n94lnffFdpqGZ/FAbNSRv2YWFh+YE17PyX1dVDIfI/yeJsoPLjzc+Gv1b1zQyk hbnRQXAoKdocghKRlfTKduC1xpnGrVdlcoo8eD3n3xNS5j5Z4gYsoYwvpQUUNIsEV/gj n/RQ== X-Received: by 10.66.119.103 with SMTP id kt7mr25933807pab.95.1409956559058; Fri, 05 Sep 2014 15:35:59 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <6ebk0a95ia9llot967jf7hpmidhh6hl4fd@4ax.com> References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <6ebk0a95ia9llot967jf7hpmidhh6hl4fd@4ax.com> From: Ian Kelly Date: Fri, 5 Sep 2014 16:35:18 -0600 Subject: Re: My backwards logic To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1409956567 news.xs4all.nl 2957 [2001:888:2000:d::a6]:44125 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77623 On Fri, Sep 5, 2014 at 3:49 PM, Seymore4Head wrote: > I am sure this has already been done, but after it was pointed out > that you don't need to test for any number that multiplies by 2 it > made me think again. > > If you start with the list [3,5,7] and step through the list of all > remaining odd numbers (step 2), and start appending numbers that won't > divide by numbers already appended in the list, that would seem like a > pretty efficient way to find all prime numbers. Indeed, this type of algorithm is known as a sieve. For a (literally) classical example, see http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes It's a nice way to find all the prime numbers up to a given limit, or it can be modified to run indefinitely high, but it's not very efficient for determining the primality of a single number.