Skip to content

Instantly share code, notes, and snippets.

@rodrigoSaladoAnaya
Last active October 12, 2016 17:52
Show Gist options
  • Save rodrigoSaladoAnaya/518d706d1f45ee63b0d49529a6ccd165 to your computer and use it in GitHub Desktop.
Save rodrigoSaladoAnaya/518d706d1f45ee63b0d49529a6ccd165 to your computer and use it in GitHub Desktop.
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)
@rodrigoSaladoAnaya
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment