Last active
September 9, 2024 12:02
-
-
Save Luna-Klatzer/3ce63521e006a917113ad4bea473fa8a to your computer and use it in GitHub Desktop.
Simple Kipper program to check if a number is prime
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
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