Skip to content

Instantly share code, notes, and snippets.

@dev001hajipro
Created August 6, 2017 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dev001hajipro/0fd3b7aa26543d54e14f8ff18f5c4794 to your computer and use it in GitHub Desktop.
Save dev001hajipro/0fd3b7aa26543d54e14f8ff18f5c4794 to your computer and use it in GitHub Desktop.
kotlinで簡単なプログラミング
fun random(min: Double = 0.0, max: Double = 1.1) = (Math.random() * (max - min + 1)) + min
fun random(min: Int = 0, max: Int = 1) = ((Math.random() * (max - min + 1)) + min).toInt()
fun randomASCII(upper: Boolean = true) = (if (upper) random(65, 90) else random(97, 122)).toChar()
fun randomString(n: Int = 5) = (1..n).map { randomASCII() }.joinToString(separator = "")
const val answer = "CAT"
fun main(args: Array<String>) {
var count = 1
while (true) {
val s = randomString(3)
val msg = if (s == answer) "FOUND : $s" else "NOT FOUND: $s"
println("${count++} $msg")
if (s == answer) {
break
}
//Thread.sleep(1000 / 60)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment