Created
August 6, 2017 21:13
-
-
Save dev001hajipro/0fd3b7aa26543d54e14f8ff18f5c4794 to your computer and use it in GitHub Desktop.
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
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