Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,28 @@
// version 1.1.2
import java.util.Random
fun montyHall(games: Int) {
var switchWins = 0
var stayWins = 0
val rnd = Random()
(1..games).forEach {
val doors = IntArray(3) // all zero (goats) by default
doors[rnd.nextInt(3)] = 1 // put car in a random door
val choice = rnd.nextInt(3) // choose a door at random
var shown: Int
do {
shown = rnd.nextInt(3) // the shown door
}
while (doors[shown] == 1 || shown == choice)
stayWins += doors[choice]
switchWins += doors[3 - choice - shown]
}
println("Simulating $games games:")
println("Staying wins $stayWins times")
println("Switching wins $switchWins times")
}
fun main(args: Array<String>) {
montyHall(1_000_000)
}