Skip to content

Instantly share code, notes, and snippets.

@candidosales
Created June 21, 2013 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save candidosales/5828868 to your computer and use it in GitHub Desktop.
Save candidosales/5828868 to your computer and use it in GitHub Desktop.
Aê...
function isPrime(n) {
if (n%1 || n<2) return false;
if (n%2==0) return (n==2);
var m=Math.sqrt(n);
for (var i=3;i<=m;i+=2) {
if (n%i==0) return false;
}
return true;
}
var x = 0;
var a = [];
while(x<100){
if(isPrime(x)) {
a.push(x);
}
x++;
}
var fs = require('fs');
var outfile = "prime.txt";
var out = a.join(",");
fs.writeFileSync(outfile, out);
console.log(out);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment