Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Birthday.rb -- happy bday to EY employees everywhere
- # with love from san diego :p, David Salamon 2008
- def no_shared_birthdays_for(people, days=365)
- return 1.0 if people == 0
- return ((days - 1.0) / 365) * no_shared_birthdays_for(people - 1, days - 1)
- end
- puts "Section one... how unlikely are collisions with different employee head counts?"
- (2..60).each {|e| puts " - with #{e} employees : #{1.0 - no_shared_birthdays_for(e)}" }
- def choose(n, m)
- m = n - m if m < n - m
- accumulator = 1.0
- (n-m).times {|i| accumulator *= (m + i + 1) }
- (n-m).times {|i| accumulator /= (i + 1)}
- accumulator.to_i
- end
- def shared_birthdays_for(people, days=365)
- return 1 if people == 0 || people == 1
- return (1.0/days) * shared_birthdays_for(people-1, days)
- end
- $employee_count = 50
- (2..10).each {|e|
- chance = choose($employee_count, e) * shared_birthdays_for(e) * no_shared_birthdays_for($employee_count - e)
- puts "chance of *exactly* #{e} people sharing a birthday: #{chance}"
- }
Add Comment
Please, Sign In to add comment