Created
June 8, 2012 03:01
-
-
Save shawjia/2893282 to your computer and use it in GitHub Desktop.
find prime
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
// find prime, example from Web Workers | |
var n = 1, | |
i, | |
q; | |
search: while (true) { | |
n += 1; | |
for (i = 2, q = Math.sqrt(n); i <= q; i++) { | |
if (n % i === 0) { | |
continue search; | |
} | |
} | |
console.log('new prime %s is found', n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment