SVN / public / code / vorlesung-02 / BirthdayParadox.cpp

Revision 11340
Date
Committerhb1003
Download
// Copyright 2016, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Author: Hannah Bast <bast@cs.uni-freiburg.de>.

#include "./BirthdayParadox.h"

// _____________________________________________________________________________
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.0 - i)/365.0;
  }
  return 1 - p;
}