Skip to content

Instantly share code, notes, and snippets.

@ngsw-taro
Created August 11, 2012 15:52
Show Gist options
  • Save ngsw-taro/3325364 to your computer and use it in GitHub Desktop.
Save ngsw-taro/3325364 to your computer and use it in GitHub Desktop.
jojo
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