Created
March 3, 2016 01:13
-
-
Save z2s8/aa19d5b40cecdf381465 to your computer and use it in GitHub Desktop.
Prime finder in crystal-lang
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
require "math" | |
NUMBER_OF_PRIMES = 1500000 | |
primes = [2] | |
test_number = 2 | |
primes_found = 0 | |
while primes_found < NUMBER_OF_PRIMES | |
test_primitiveness = true | |
i = 0 | |
while (primes.size > i && primes[i] <= Math.sqrt(test_number) && test_primitiveness) | |
if test_number % primes[i] == 0 | |
test_primitiveness = false | |
end | |
i += 1 | |
end | |
if test_primitiveness | |
primes << test_number | |
primes_found += 1 | |
end | |
test_number += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test run on
Intel(R) Core(TM) 2 Quad Q9400 @ 2.66GHz
withCrystal 0.11.1
: