Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created September 4, 2012 18:47
Show Gist options
  • Save jubishop/3624886 to your computer and use it in GitHub Desktop.
Save jubishop/3624886 to your computer and use it in GitHub Desktop.
Girl Probability
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