Created
September 4, 2012 18:47
-
-
Save jubishop/3624886 to your computer and use it in GitHub Desktop.
Girl Probability
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
girl = 0 | |
boy = 1 | |
at_least_one_girl = 0 | |
all_girls = 0 | |
1000000.times{ | |
one_girl = false | |
num_girls = 0 | |
3.times { | |
if (rand(2) == girl) | |
one_girl = true | |
num_girls += 1 | |
end | |
} | |
at_least_one_girl += 1 if (one_girl) | |
all_girls += 1 if (num_girls == 3) | |
} | |
puts at_least_one_girl / all_girls.to_f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment