Assume a year has 365 days, what is the probability among 50 students, that at least two having the same birthday?
Let’s consider this: what is the probability that all 50 students are having different birthdays?
.
P is the permutation function, so P(365, 50) is the total permutation of choosing 50 out of 365. We are choosing 50 days out of a year which is the students having different birthdays. The total number of possibilities is 36550.
So the answer will be 1 – 0.03 = 97%.
Let’s consider this: what is the probability that all only two (exactly two) share the birthday?
Let’s solve this step by step:
- Pick two out of 50 students, which is C(50, 2) i.e. C is the combination function.
- Pick one out of 365 days, which is used as the same birthday, that is 365 solutions.
- Among the 48 students, their birthdays should be among the rest 364 days, which is P(364, 48)
Therefore, the probability that all only two (exactly two) share the birthday is:
C++ solution to compute the probability
Let’s create a simple console application in C/C++.
1 2 3 4 5 6 7 8 9 10 11 12 13 | // birthday.c // https://helloacm.com/what-is-the-probability-of-two-sharing-birthday/ #include <stdio.h> int main() { double r = 1.0; for (int i = 0; i < 48; i ++) { r *= (364 - i) / 365.0; } r = r * (25.0 * 49) / 365.0; printf("%.5lf\n", r); return 0; } |
// birthday.c // https://helloacm.com/what-is-the-probability-of-two-sharing-birthday/ #include <stdio.h> int main() { double r = 1.0; for (int i = 0; i < 48; i ++) { r *= (364 - i) / 365.0; } r = r * (25.0 * 49) / 365.0; printf("%.5lf\n", r); return 0; }
Compile above using gcc birthday.c -o birthday. Run ./birthday:
0.11485
That means the probability of exactly two out of 50 having the same birthday is 11.485%.
Useful Link
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: How to Call COM Object from Visual Studio C++?
Next Post: How to Add Search Function to A Blog?