Created
May 2, 2011 00:40
-
-
Save nbashaw/951041 to your computer and use it in GitHub Desktop.
Program to find the probability that n people all have different birthdays
This file contains 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
# Program to find the probability that n people all have different birthdays | |
class ::Fixnum | |
def factorial | |
result = self | |
self.times do |n| | |
result *= (self - n) if not n == 0 | |
end | |
result | |
end | |
end | |
print 'How many people? ' | |
n = gets.to_i | |
result = (365.factorial / (365 - n).factorial).to_f / (365 ** n).to_f | |
puts "Probability their birthdays are unique: #{result}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment