Skip to content

Instantly share code, notes, and snippets.

@AndersonTorres
Created November 18, 2021 00:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndersonTorres/e1c9a7b50e53d19e66e99019b3c8f280 to your computer and use it in GitHub Desktop.
Save AndersonTorres/e1c9a7b50e53d19e66e99019b3c8f280 to your computer and use it in GitHub Desktop.
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