Bulls and cows: Difference between revisions
→{{header|Kotlin}}: Update
Not a robot (talk | contribs) (Add ABC) |
(→{{header|Kotlin}}: Update) |
||
Line 4,176:
=={{header|Kotlin}}==
<syntaxhighlight lang="
const val MAX_GUESSES = 20 // say
fun main(
// generate a 4 digit random number from 1234 to 9876 with no zeros or repeated digits
val num: String = generateSequence { (1234..9876).random().toString() }.first { '0' !in it && it.toSet().size == 4 }
println("All guesses should have exactly 4 distinct digits excluding zero.")
Line 4,195 ⟶ 4,189:
while (true) {
print("Enter your guess : ")
val guess =
if (guess == num) {
println("You've won with ${++guesses} valid guesses!")
}
val n = guess.toIntOrNull()
Line 4,247 ⟶ 4,241:
You've won with 9 valid guesses!
</pre>
=={{header|Lasso}}==
This game uses an HTML form to submit the answer. The random number and history are stored in a session using Lasso's built in session management.
|