Skip to content

Instantly share code, notes, and snippets.

@st
Created February 16, 2012 13:25
Show Gist options
  • Save st/1844817 to your computer and use it in GitHub Desktop.
Save st/1844817 to your computer and use it in GitHub Desktop.
Monty Hall Problem
@wins_sticky = 0
@wins_change = 0
@nb_parties = 1000
@possibles = [0, 1, 2]
def play
winner = rand(3)
first_choose = rand(3)
others = @possibles - [first_choose]
discarded = others.include?(winner) ? (others - [winner]).first : others[rand(2)]
@wins_sticky +=1 if first_choose==winner
@wins_change +=1 if (others - [discarded]).first==winner
end
@nb_parties.times do
play
end
puts "wins_sticky % #{@wins_sticky.to_f / @nb_parties}"
puts "wins_change % #{@wins_change.to_f/ @nb_parties}"
@st
Copy link
Author

st commented Feb 16, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment