Skip to content

Instantly share code, notes, and snippets.

@siosio siosio/gist:3329207
Created Aug 12, 2012

Embed
What would you like to do?
素数の時にJOJOと出力するKotlin
package jojo
fun main(args: Array<String>) {
jojoIterator() forEach {println(it)}
}
fun jojoIterator(): java.util.Iterator<Any> {
fun next(number: Int): Any {
if (number == 1) {
number
} else if (number == 2) {
"JOJO"
} else {
if ((2..Math.sqrt(number.toDouble()).toInt()).any {number % it == 0}) {
number
} else {
"JOJO"
}
}
}
var number = 1
return iterate {
if (number <= 100) {
next(number++)
} else {
null
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.