Skip to content

Instantly share code, notes, and snippets.

@Luna-Klatzer
Last active September 9, 2024 12:02
Show Gist options
  • Save Luna-Klatzer/3ce63521e006a917113ad4bea473fa8a to your computer and use it in GitHub Desktop.
Save Luna-Klatzer/3ce63521e006a917113ad4bea473fa8a to your computer and use it in GitHub Desktop.
Simple Kipper program to check if a number is prime
def isPrime(n: num) -> bool {
if (n <= 1) {
return false; // Never a prime
} else if (n == 2 || n == 3) {
return true; // Base primes
} else if (n % 2 == 0 || n % 3 == 0) {
return false; // Easy base prime checks
}
for (var i: num = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0) {
return false;
}
}
return true;
}
var numToCheck: num = 7; // is prime
print(f"{numToCheck} - isPrime: {isPrime(numToCheck)}");
numToCheck = 9; // is not prime
print(f"{numToCheck} - isPrime: {isPrime(numToCheck)}");
numToCheck = 97; // is prime
print(f"{numToCheck} - isPrime: {isPrime(numToCheck)}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment