Skip to content

Instantly share code, notes, and snippets.

@shawjia
Created June 8, 2012 03:01
Show Gist options
  • Save shawjia/2893282 to your computer and use it in GitHub Desktop.
Save shawjia/2893282 to your computer and use it in GitHub Desktop.
find prime
// 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