Quote:
Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?
The solution is said to be yes, because you have 1/3 probability to stay and 2/3 probability to switch.
Quote:
' does not switch
For c = 1 To 10000
car = Rand(0, 2)
If car = 0 Then
x = x + 1
End If
Next c
'always switches
For c = 1 To 10000
car = Rand(0, 2)
If car = 2 Then
y = y + 1
ElseIf car = 1 Then
y = y + 1
End If
Next c
Quote:
For c = 1 To 10000
car = Rand(0, 2)
If car Xor 1 = 0 Then
host = 2
ElseIf car Xor 2 = 0 Then
host = 1
End If
If host = 1 Then
If car = 0 Then
n = n + 1
End If
ElseIf host = 2 Then
If car = 0 Then
n = n + 1
End If
End If
Next c
'my version - switch is always made
For c = 1 To 10000
car = Rand(0, 2)
' host must decide which door to open based on the location of car. Since he always opens a losing door....
If car Xor 1 = 0 Then 'if car is in door 1
host = 2 'host will open door 2
ElseIf car Xor 2 = 0 Then
host = 1
End If
If host = 1 Then ' if host opens door 1
If car = 2 Then 'switch is made to door 2, is there a car?
z = z + 1 ' win
End If
ElseIf host = 2 Then
If car = 1 Then
z = z + 1
End If
End If
Next c
With this algorithm, the probability changes to 1/3 and 1/3 and shows that you have equal chance to win, if you do or do not switch doors.