Skip to content

Instantly share code, notes, and snippets.

@gbechtold
Created August 15, 2015 14:54
Show Gist options
  • Save gbechtold/4f52c5c23a510468fa0e to your computer and use it in GitHub Desktop.
Save gbechtold/4f52c5c23a510468fa0e to your computer and use it in GitHub Desktop.
function IsPrime(int) {
for(i=2;i<int;i++) {
var rest;
var result;
rest = int%i;
//No Prime
console.log(rest);
if((rest==0)) {console.log('0R');result=false;break;}
//Prime
if((rest>0&&i==int-1)) {console.log('Prime');result=true;break;}
}
return result;
}
console.log(IsPrime(4));
console.log('-----');
console.log(IsPrime(5));
// EUL 6
var IterationCounter;
var IterationMax=10000; // Iterations -1
var Counter=1;
var PrimeCounter=1;
function IsPrime(int) {
for(i=2;i<int;i++) {
var rest;
var result;
rest = int%i;
//No Prime
//console.log(rest);
if((rest==0)) {//console.log('0R');
result=false;
break;}
//Prime
if((rest>0&&i==int-1)) {//console.log('Prime');
result=true;
break;}
}
return result;
}
//6th prime is 13
console.log(IsPrime(4));
console.log(IsPrime(5));
do {
Counter++;
// console.log(Counter);
if(IsPrime(Counter)==true){PrimeCounter++}
// console.log('PrimeIterations:'+PrimeCounter);
} while (PrimeCounter<=IterationMax)
// Result
console.log("PrimeCounter: "+PrimeCounter);
console.log("Number: "+Counter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment