Skip to content

Instantly share code, notes, and snippets.

@JunJaBoy
Created April 28, 2024 06:03
Show Gist options
  • Save JunJaBoy/3b42325cf7483d9cbad9686f0b8f4438 to your computer and use it in GitHub Desktop.
Save JunJaBoy/3b42325cf7483d9cbad9686f0b8f4438 to your computer and use it in GitHub Desktop.
Best way to check if the number is prime
val Int.isPrime: Boolean
get() {
if (this <= 1) return false
for (i in 2..<this) {
if (this % i == 0) return false
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment