Last active
August 29, 2015 14:03
-
-
Save muayyad-alsadi/643b2860e82ac1e1ce80 to your computer and use it in GitHub Desktop.
primes in lua
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
function get_primes (n) | |
compo={} | |
primes={} | |
for i=2,n do | |
if not compo[i] then | |
primes[i]=true | |
for j=i*2,n,i do | |
compo[j]=true | |
end | |
end | |
end | |
return primes | |
end | |
for k,v in pairs(get_primes(10000)) do | |
print(k) | |
end | |
t0=os.clock() | |
for i=0,500 do | |
get_primes(10000) | |
end | |
print(os.clock()-t0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment