Created
November 18, 2021 00:35
-
-
Save AndersonTorres/e1c9a7b50e53d19e66e99019b3c8f280 to your computer and use it in GitHub Desktop.
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
fn is_prime(comptime T: type, | |
n: T) bool { | |
var d: T = 2; | |
var exausted: bool = false; | |
var found: bool = false; | |
if (n < 0) return is_prime(-n); | |
if (n == 0 or n == 1) return false; | |
while (!exausted and !found) { | |
if (d*d > n) | |
exausted = true; | |
else if (n%d == 0) | |
found == true; | |
else | |
d += 1; | |
} | |
return !exausted; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment