Created
July 2, 2011 16:21
-
-
Save samrat/1061065 to your computer and use it in GitHub Desktop.
a naive approach to prime number generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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