Last active
May 6, 2016 11:02
-
-
Save cutalion/768b3d179102fa8aa01c7228a807a6e1 to your computer and use it in GitHub Desktop.
Monty Hall problem experiment https://en.wikipedia.org/wiki/Monty_Hall_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
N = 10_000 | |
matched1 = 0 | |
matched2 = 0 | |
N.times do | |
seq = [1, 0, 0].shuffle | |
guess = rand(3) | |
matched1 += 1 if seq[guess].eql?(1) | |
index_zero = seq.each_with_index do |item, index| | |
break index if (index != guess && item == 0) | |
end | |
seq.delete_at(index_zero) | |
guess = guess - 1 if guess > index_zero | |
matched2 += 1 if seq[guess].eql?(0) | |
end | |
puts matched1 / N.to_f | |
puts matched2 / N.to_f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment