Created
August 11, 2012 15:52
-
-
Save ngsw-taro/3325364 to your computer and use it in GitHub Desktop.
jojo
This file contains 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
fun main(args : Array<String>) { | |
for(i in 1..100) { | |
i.jojo() | |
} | |
} | |
private fun Int.jojo() { | |
val s = if(this.isPrime()) "JOJO!" else "$this" | |
println(s) | |
} | |
private fun Int.isPrime() : Boolean { | |
check(this > 0) | |
if(this == 1) return false | |
if(this == 2) return true | |
if(this % 2 == 0) return false | |
for(i in Array((this - 3) / 4) { | |
it * 2 + 3 | |
}) { | |
if(this % i == 0 && this != i) { | |
return false | |
} | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment