Skip to content

Instantly share code, notes, and snippets.

@gonaumov
Created April 25, 2022 22:21
Show Gist options
  • Save gonaumov/4b90c10bd5cc9f42516da2955c5ca284 to your computer and use it in GitHub Desktop.
Save gonaumov/4b90c10bd5cc9f42516da2955c5ca284 to your computer and use it in GitHub Desktop.
Russian roulette with Kotlin
package com.company
fun main() {
for ((index, shot) in BooleanArray(6) { false }.apply {
this[(0 until this.size).random()] = true
this.shuffle()
}.withIndex()) {
if (shot) {
println("Iteration ${index + 1}. You are dead ..")
break
}
println("Iteration ${index + 1}. Still alive ..")
Thread.sleep(1000)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment