20 lines
445 B
Text
20 lines
445 B
Text
var switchWins = 0
|
|
var stayWins = 0
|
|
|
|
for plays in 0..1000000 {
|
|
var doors = [0 ,0, 0]
|
|
var winner = rnd(max: 3)
|
|
doors[winner] = 1
|
|
var choice = rnd(max: 3)
|
|
var shown = rnd(max: 3)
|
|
|
|
while doors[shown] == 1 || shown == choice {
|
|
shown = rnd(max: 3)
|
|
}
|
|
|
|
stayWins += doors[choice]
|
|
switchWins += doors[3 - choice - shown]
|
|
}
|
|
|
|
print("Staying wins \(stayWins) times.")
|
|
print("Switching wins \(switchWins) times.")
|