Skip to content

Instantly share code, notes, and snippets.

@herber
Created July 30, 2017 19:11
Show Gist options
  • Save herber/2c8a37d819e507c0ec81f031c282fb7a to your computer and use it in GitHub Desktop.
Save herber/2c8a37d819e507c0ec81f031c282fb7a to your computer and use it in GitHub Desktop.
A simple, inefficient algorithm for generating prime numbers.
const fs = require('fs');
let last = 0;
const p = () => {
const n = last + 1;
for (let i = 2; i < n; i++) {
if (n % i === 0) {
return;
}
}
fs.appendFileSync(__dirname + '/primes', n + '\n');
}
for (;;) {
p();
last = last + 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment