Skip to content

Instantly share code, notes, and snippets.

@undees
Created November 14, 2011 03:11
Show Gist options
  • Save undees/1363148 to your computer and use it in GitHub Desktop.
Save undees/1363148 to your computer and use it in GitHub Desktop.
Monty Hall Monte Carlo
change_mind = true
attempts = 1000
successes = 0
attempts.times do
prize_door = rand(3)
guess_door = rand(3)
other_doors = [0, 1, 2] - [prize_door, guess_door].uniq
empty_door = other_doors.sort_by { rand }.first
alt_door = ([0, 1, 2] - [guess_door, empty_door]).first
final_guess = change_mind ? alt_door : guess_door
successes += 1 if final_guess == prize_door
end
win_percent = successes.to_f / attempts.to_f * 100.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment