Created
May 5, 2016 15:23
-
-
Save soccermitchy/d01953e34e99b1953e398c32e3138e64 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes implementation in haxe
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
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