Last active
October 12, 2016 17:52
-
-
Save rodrigoSaladoAnaya/518d706d1f45ee63b0d49529a6ccd165 to your computer and use it in GitHub Desktop.
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 get_atmos_list = { input -> | |
def time_start = System.currentTimeMillis() | |
def atoms = [2, 3] | |
def fill_list = { n -> | |
def sqrt = Math.sqrt(n) as int | |
def is_atom = true | |
for(i = 0; i <= sqrt - 1; i++) { | |
if(n % atoms[i] == 0) { | |
is_atom = false | |
return | |
} | |
} | |
if(is_atom) { atoms << n } | |
} | |
def next = 4 | |
while(next < input) { | |
fill_list(next++) | |
} | |
def time_end = System.currentTimeMillis() | |
def time_diff = (time_end - time_start) | |
return [ | |
atoms: atoms, | |
time: time_diff | |
] | |
} | |
//println get_atmos_list(10) | |
//println get_atmos_list(100) | |
//println get_atmos_list(1000) | |
//println get_atmos_list(10000) | |
println get_atmos_list(1_00_000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Incluso en la versión WEB uso lo que comentas de n=+2 :P https://github.com/rodrigoSaladoAnaya/criba_eratostenes/blob/master/index.js#L26