Skip to content

Instantly share code, notes, and snippets.

@benek
Created January 13, 2012 04:37
Show Gist options
  • Save benek/1604716 to your computer and use it in GitHub Desktop.
Save benek/1604716 to your computer and use it in GitHub Desktop.
Coding Kata 1
package codingdojo.numerosprimos;
/**
* @author benek
* Date: 12/01/12
* Time: 20:57
* www.javamexico.org
*/
public class NumerosPrimos {
public static void main(String args[]){
long inicio = System.currentTimeMillis();
int i = 2;
int primo = 0;
for (;;){
if (esPrimo(i)){
primo++;
}
if (primo == 10001){
break;
}
i++;
}
System.out.println(i);
long termino = System.currentTimeMillis();
System.out.println(termino - inicio);
}
private static boolean esPrimo(int numero){
if (numero == 2 || numero == 3){
return true;
} else {
for (int i = 2; i <= (int) Math.sqrt(numero); i++){
if (numero%i == 0){
return false;
}
}
return true;
}
}
}
@benek
Copy link
Author

benek commented Jan 13, 2012

Yo sí ya lo medí aquí en local y efectivamente sale en el intervalo que mencionas "luego luego" aka "en chinga".

@neodevelop
Copy link

Deberías de ir al siguiente Dojo ese Chochos :D...

@chochos
Copy link

chochos commented Jan 13, 2012

Sí, pues a ver si al próximo...

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