Skip to content

Instantly share code, notes, and snippets.

@samrat
Created July 2, 2011 16:21
Show Gist options
  • Save samrat/1061065 to your computer and use it in GitHub Desktop.
Save samrat/1061065 to your computer and use it in GitHub Desktop.
a naive approach to prime number generation
def naiveprime(n):
primelist = []
for num in range(int(n+1)):
prime= True
for i in range(2,int(num)):
if (num%i)==0:
prime=False
break
if prime==True: primelist.append(num)
return primelist[2:]
#runtime calculation
import time
tStart=time.time()
naiveprime(6000)
print("Program complete")
print("Time taken:", time.time()-tStart,"seconds")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment