Created
August 12, 2012 02:39
-
-
Save siosio/3329207 to your computer and use it in GitHub Desktop.
素数の時にJOJOと出力するKotlin
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
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