Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created January 4, 2011 00:16
Show Gist options
  • Select an option

  • Save JoshCheek/764220 to your computer and use it in GitHub Desktop.

Select an option

Save JoshCheek/764220 to your computer and use it in GitHub Desktop.
monty hall style problem
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