Created
April 28, 2024 06:03
-
-
Save JunJaBoy/3b42325cf7483d9cbad9686f0b8f4438 to your computer and use it in GitHub Desktop.
Best way to check if the 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
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