Ask HN: A random maths problem we started discussing at work
How many people would you need in a group to make it likely that at least one member had a birthday on each of 365 days of the year?
Let's ignore leap years and define likely as >50% probability.
15 comments
[ 3.9 ms ] story [ 45.9 ms ] threadBut, it's worth noting that if this interests you, Project Euler almost certainly will as well and is worth checking it out if you don't already know about it:
http://projecteuler.net/
EDIT: So if you're wondering why I got a different brute force result from other users, it's because I had a stupid bug. I was looking at the ratio of meeting the criteria to the ratio of not meeting it, not the ratio of meeting it to total.
23 people is a 50% chance, 57 is a 99% chance, 367 is 100% chance (including leap years).
http://en.wikipedia.org/wiki/Birthday_problem
http://en.wikipedia.org/wiki/Coupon_collector%27s_problem
The formula in the article (1/2 + n*gamma + n log n) gives 2365 for the expected number, but this is different than "at least 50% chance".
Thanks for the link!
import java.util.Random;
public class Birthday {
private static Random rand = new Random(System.currentTimeMillis());
public static void main(String... args) {
Let n be the number of people needed. Probability that a person's birthday is not today: 364/365
Prob. that no one's birthday is today: (364/365)^n
Prob. that someone's birthday is today: 1 - (364/365)^n
Prob. that someone's birthday covers every day: (1 - (364/365)^n)^365
Setting equal to 0.5 and solving, I get n==2284, which is close to metaphyze's brute force number.