Created
August 15, 2015 14:54
-
-
Save gbechtold/4f52c5c23a510468fa0e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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)); |
This file contains hidden or 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
// 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