Skip to content

Instantly share code, notes, and snippets.

@nbashaw
Created May 2, 2011 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbashaw/951041 to your computer and use it in GitHub Desktop.
Save nbashaw/951041 to your computer and use it in GitHub Desktop.
Program to find the probability that n people all have different birthdays
# 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