Skip to content

Instantly share code, notes, and snippets.

@bgits
Last active December 19, 2015 00:29
Show Gist options
  • Save bgits/5869062 to your computer and use it in GitHub Desktop.
Save bgits/5869062 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
var fs = require('fs');
var outfile = "primes.txt";
var primes = new Array();
var i = 2;
var factor = function(n){
while (primes.length<100)
{
if (n%i !== 0 && i === n-1 ||n===2){
primes.push(n);
i = 2;
n++;
}else if(n%i === 0){
i = 2;
n++;
}else {
i++;
}
}
};
factor(2);
console.log(primes + " ");
fs.writeFileSync(outfile, primes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment