instead of writing this line
for i in range( 2, x ):
Can't we use the cache to build a prime list for our advantage?
for i in primes_list:
In this case the cache is built using a python dictionary. We can check this dictionary first before computing whether a given number is prime.
for i in range(2, x):
This syntax counts from 2 to x-1 and assigns the number to i. We have to do this to test if x is ever divisible by i without a remainder. If we ever modulus x by i and get 0 (no remainder) then x is not prime.
Update - My new laptop is significantly faster at computing primes:
>>> from time import time >>> from primer import Primer >>> p = Primer() >>> s1 = time();p.is_prime( 97352613 );e1 = time() False >>> s2 = time();p.is_prime( 97352613 );e2 = time() False >>> e1 - s1 2.10681414604187 >>> e2 - s2 0.01556706428527832

Remarkbox