Created
July 30, 2017 19:11
-
-
Save herber/2c8a37d819e507c0ec81f031c282fb7a to your computer and use it in GitHub Desktop.
A simple, inefficient algorithm for generating prime numbers.
This file contains 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
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