Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub doors()
- ''''expected vs actual result: http://i.imgur.com/uEA2AZj.png
- ''''run as a VBA Macro in Excel
- Dim dCount As Long 'door count
- Dim car As Long 'used to randomly pick which door has the car
- Dim choice As Long 'used to pick which door the contestant picks
- Dim itr As Long 'number of iterations
- Dim wins As Double 'number of wins
- itr = 100000
- dCount = 3
- wins = 0
- For i = 1 To itr
- 'rnd double between 0 and 1, * door count, add 0.5 to account for rounding.
- car = Round((Math.Rnd * dCount) + 0.5, 0)
- choice = Round((Math.Rnd * dCount) + 0.5, 0)
- 'If the door you picked "choice" is not the car,
- 'then the host has shown that the remaining door *is* the car.
- 'Therefore, by switching you win.
- If car <> choice Then
- wins = wins + 1 'increase wins
- End If
- 'if the door you picked "choice" is the car,
- 'then by switching you will lose.
- 'Nothing done since winrate is not increased.
- Next i
- MsgBox "Expected: " & Round((dCount - 1) / dCount * 100, 2) & "%" _
- & vbNewLine & "Actual: " & Round(wins / itr * 100, 2) & "%"
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement