Created
January 4, 2011 00:16
-
-
Save JoshCheek/764220 to your computer and use it in GitHub Desktop.
monty hall style problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| switch = 0 | |
| stay = 0 | |
| 100_000.times do | |
| doors = [ :goat , :goat , :goat , :car ].shuffle | |
| guess = rand doors.size | |
| if doors[guess] == :car | |
| stay += 1 | |
| else | |
| doors.delete_at guess | |
| doors.delete_at doors.index(:goat) | |
| new_guess = rand(doors.size) | |
| switch += 1 if doors[new_guess] == :car | |
| end | |
| end | |
| # switch 37% | |
| switch # => 37489 | |
| # stay 25% | |
| stay # => 25000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment