Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Basic Math/Birthday-paradox-problem/Birthday-paradox-solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <bits/stdc++.h>
using namespace std;
// C++ program to approximate number of people in Birthday Paradox
// problem
// Returns approximate number of people for a given probability
int find(double p)
{
if (p != 1)
return ceil(sqrt(2 * 365 * log(1 / (1 - p))));
else return 366;
}
int main()
{

/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
cout << find(0.50);
}

7 changes: 7 additions & 0 deletions Basic Math/Birthday-paradox-problem/Problem-statement.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
How many people must be there in a room to make the probability 100% that at-least two people in the room have same birthday?

Answer: 367 (since there are 366 possible birthdays, including February 29).

How many people must be there in a room to make the probability 50% that at-least two people in the room have same birthday?
Answer: 23
The number is surprisingly very low. In fact, we need only 70 people to make the probability 99.9 %.