Skip to content

Instantly share code, notes, and snippets.

@soccermitchy
Created May 5, 2016 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soccermitchy/d01953e34e99b1953e398c32e3138e64 to your computer and use it in GitHub Desktop.
Save soccermitchy/d01953e34e99b1953e398c32e3138e64 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes implementation in haxe
package;
import sys.FileSystem;
class Main
{
static function main()
{
var numbers = [
for (i in 2...100) {
isPrime(i);
}
];
var curPrime = 1;
for (prime in numbers) {
curPrime = curPrime + 1;
trace(curPrime + "\t" + prime);
}
}
static function isPrime(possiblePrime:Int):Bool {
if (possiblePrime == 2) return true;
var maximumTestable = Math.ceil(Math.sqrt(possiblePrime));
for (primeTest in 2...maximumTestable+1) {
if (possiblePrime % primeTest == 0) return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment