Latest recipes tagged "prime_number"http://code.activestate.com/recipes/tags/prime_number/new/2013-01-19T03:58:05-08:00ActiveState Code RecipesGenreate x digits prime number in python, version 1 (Python) 2013-01-06T20:25:20-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578404-genreate-x-digits-prime-number-in-python-version-1/ <p style="color: grey"> Python recipe 578404 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>). </p> <p>This is a prime number generator in python that I put together for an article I wrote <a href="http://thelivingpearl.com/2013/01/06/how-to-find-prime-numbers-in-python/">How To Find Prime Numbers In Python</a>. The script will generate a prime number of x digits for small numbers, less than 10. </p> Find the nth prime in python (Python) 2013-01-06T20:23:21-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578403-find-the-nth-prime-in-python/ <p style="color: grey"> Python recipe 578403 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>). </p> <p>This is a nth prime number generator in python that I put together for an article I wrote <a href="http://thelivingpearl.com/2013/01/06/how-to-find-prime-numbers-in-python/">How To Find Prime Numbers In Python</a></p> "Effcient" Prime Number Generator in Python (Python) 2013-01-19T03:58:05-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578402-effcient-prime-number-generator-in-python/ <p style="color: grey"> Python recipe 578402 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>). </p> <p>This is a prime number generator in python that I put together for an article I wrote <a href="http://thelivingpearl.com/2013/01/06/how-to-find-prime-numbers-in-python/">How To Find Prime Numbers In Python</a></p> <p>Please Note. This is only efficient per the article discussing this code in the link above. See comments for a better library to generate prime numbers.</p> Prime Number Generator in Python (half effcient) (Python) 2013-01-06T20:20:49-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578401-prime-number-generator-in-python-half-effcient/ <p style="color: grey"> Python recipe 578401 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>). </p> <p>This is a simple prime number generator in python that I put together for an article I wrote <a href="http://thelivingpearl.com/2013/01/06/how-to-find-prime-numbers-in-python/">How To Find Prime Numbers In Python</a>. In this one we cut the numbers in half so it is only slightly more efficient than the simplest prime number generator. </p> <p>Note: There are more efficient ways to do this. Please look at my other recipes. </p> Simple Prime Number Generator in Python (Python) 2013-01-06T20:18:38-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578400-simple-prime-number-generator-in-python/ <p style="color: grey"> Python recipe 578400 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>). </p> <p>This is a simple prime number generator in python that I put together for an article I wrote <a href="http://thelivingpearl.com/2013/01/06/how-to-find-prime-numbers-in-python/">How To Find Prime Numbers In Python</a>.</p> <p>Note: There are more efficient ways to do this. Please look at my other recipes. </p> A fast & memory-wise prime number generator up to N (Python) 2010-08-13T18:28:00-07:00robert.william.hankshttp://code.activestate.com/recipes/users/4174481/http://code.activestate.com/recipes/577357-a-fast-memory-wise-prime-number-generator-up-to-n/ <p style="color: grey"> Python recipe 577357 by <a href="/recipes/users/4174481/">robert.william.hanks</a> (<a href="/recipes/tags/fast/">fast</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>Using python 2.6 &amp; numpy. This code was first posted <a href="http://stackoverflow.com/questions/2897297/speed-up-bitstring-bit-operations-in-python/2908512#2908512">here</a></p> Find Prime Numbers in python (Python) 2010-06-12T08:22:40-07:00Giannis Fysakishttp://code.activestate.com/recipes/users/4174072/http://code.activestate.com/recipes/577259-find-prime-numbers-in-python/ <p style="color: grey"> Python recipe 577259 by <a href="/recipes/users/4174072/">Giannis Fysakis</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/primality_testing/">primality_testing</a>, <a href="/recipes/tags/prime/">prime</a>, <a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>). Revision 2. </p> <p>The algorithm is based on the idea <br /> that the next larger prime after one prime is the sum of the two smaller previous minus three prime numbers back. For the first five prime numbers 2,3,5,7,11 this pattern is not true also it is not true if the number is a composite number (including of course if the number's square root is integer). </p> <p>Example trying to find the tenth prime</p> <p>so lets play with numbers 17(minus 3 from Next,position 7), 19(minus 2 from Next,position 8), 23(minus 1 from Next,position 9) and number Next at position 10 :</p> <p>hmmm ... if we add 19 and 23 we get 42, but 42 minus 17 equals 25 which isn't a prime :(</p> <p>In order to correct this we assume that 25 is the next prime number ( temporary holding the tenth position) finally to get the real Next prime number we take 23 + 25 = 48 , we subtract 19 and we get 29 which finally it takes the tenth position ( because it deserves it :P)</p> Prime Number Generator Checker (Python) 2008-10-28T12:14:03-07:00TheMachineCharmerhttp://code.activestate.com/recipes/users/4167676/http://code.activestate.com/recipes/576543-prime-number-generator-checker/ <p style="color: grey"> Python recipe 576543 by <a href="/recipes/users/4167676/">TheMachineCharmer</a> (<a href="/recipes/tags/number_theory/">number_theory</a>, <a href="/recipes/tags/primality_testing/">primality_testing</a>, <a href="/recipes/tags/prime_number/">prime_number</a>). Revision 2. </p> <p>This program implements primality testing function. The function is then used to generate prime numbers in the given range.</p>