init
This commit is contained in:
47
hardfindprime.py
Normal file
47
hardfindprime.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from timer import timing_function
|
||||
|
||||
|
||||
def isprime(number, primelist):
|
||||
"""
|
||||
checks if a number is prime by finding dividing it by every other prime
|
||||
below floor(number / 2)
|
||||
"""
|
||||
for prime in primelist:
|
||||
if prime <= number // 2 and number % prime == 0:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@timing_function
|
||||
def findprimesto(primecap):
|
||||
"""
|
||||
finds numprimes count of prime numbers
|
||||
"""
|
||||
primelist = [2]
|
||||
testnum = 3
|
||||
|
||||
while testnum < primecap:
|
||||
|
||||
if isprime(testnum, primelist):
|
||||
primelist.append(testnum)
|
||||
|
||||
testnum += 2
|
||||
|
||||
return primelist
|
||||
|
||||
@timing_function
|
||||
def findxprimes(x):
|
||||
"""
|
||||
finds numprimes count of prime numbers
|
||||
"""
|
||||
primelist = [2]
|
||||
testnum = 3
|
||||
|
||||
while len(primelist) < x:
|
||||
|
||||
if isprime(testnum, primelist):
|
||||
primelist.append(testnum)
|
||||
|
||||
testnum += 2
|
||||
|
||||
return primelist
|
||||
Reference in New Issue
Block a user