Skip to content

Instantly share code, notes, and snippets.

@djacobs djacobs/primes.js
Created Nov 12, 2011

Embed
What would you like to do?
Euler 7 (for Jake)
primecount=1;
i=3;
while(primecount < 10001)
{
// console.log("looking at " + i);
isprime = true;
for (j=(Math.floor(Math.sqrt(i))); j > 1; j--) {
// for (j=2; j < (Math.floor(Math.sqrt(i)) + 1); j++ ) {
// console.log("looking at " + i + " " + j);
if (i%j==0) { isprime = false; }
}
if (isprime) {
lastprime=i;
primecount++;
//console.log(i + " is prime number " + primecount);
}
i+=2;
}
console.log(lastprime + " is the " + primecount + " prime number");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.