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
| # This program simulates the Monty Hall problem (https://en.wikipedia.org/wiki/Monty_Hall_problem). | |
| # Specifically, it counts how often the contestant wins by switching doors when given the choice | |
| # by the game show host. | |
| def contestant_wins? | |
| doors = [:car, :goat, :goat] | |
| indexes = 0...doors.size | |
| player_first_choice = rand(doors.size) | |
| host_choice = (indexes.select {|i| i != player_first_choice && doors[i] == :goat}).sample | |
| player_second_choice = indexes.find {|i| i != player_first_choice && i != host_choice} |