diff --git a/Basic Math/Birthday-paradox-problem/Birthday-paradox-solution.cpp b/Basic Math/Birthday-paradox-problem/Birthday-paradox-solution.cpp new file mode 100644 index 0000000..3f24df5 --- /dev/null +++ b/Basic Math/Birthday-paradox-problem/Birthday-paradox-solution.cpp @@ -0,0 +1,21 @@ +#include +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); +} + diff --git a/Basic Math/Birthday-paradox-problem/Problem-statement.txt b/Basic Math/Birthday-paradox-problem/Problem-statement.txt new file mode 100644 index 0000000..70cfbf4 --- /dev/null +++ b/Basic Math/Birthday-paradox-problem/Problem-statement.txt @@ -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 %. \ No newline at end of file