a thoughtful web.
Good ideas and conversation. No ads, no tracking.   Login or Take a Tour!
comment
user-inactivated  ·  1906 days ago  ·  link  ·    ·  parent  ·  post: The Strong Law of Small Numbers

Generating all primes is just as easy as testing for primes:

    import math

def is_prime(n):

for m in range(2,int(math.sqrt(n))+1):

if n%m == 0:

return False

return True

def primes():

n = 2

while True:

if is_prime(n):

yield n

n += 1

for p in primes():

print p

it's just that we don't have useful ways to generate primes.