Skip to content

@listrophy /gist:44189
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
The Birthday Problem!
lower_bound = (ARGV.shift || 2).to_i
upper_bound = (ARGV.shift || 35).to_i
iterations = (ARGV.shift || 20_000).to_i
(lower_bound..upper_bound).each do |person_count|
matches = 0
iterations.times do
matches += 1 if (1..person_count).map{|p| rand(365)}.uniq!
end
puts "Person count: %3d Success: %3.1f" %
[person_count, matches * 100.0 / iterations]
end
__END__
$ ruby birthday.rb 22 24
Person count: 22 Success: 47.6
Person count: 23 Success: 50.6
Person count: 24 Success: 54.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.