// Copyright 2016, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Author: Hannah Bast <bast@cs.uni-freiburg.de>.
// Compute the probability that in a group of n people, there are at least two
// with the same birthday. This probability is 1 - 1 * 364/365 * 363/365 * ... *
// (365-n+1)/365.
//
// TODO(bast): border cases still missing.
double probabilitySameBirthday(int n) {
// First compute the probability p that all n people have different birthdays.
double p = 1.0;
for (int i = 1; i < n; i++) {
p = p * (365 - i)/365;
}
return 1 - p;
}