Problem 597. The Birthday Phenomenon
First off, leap years are not being considered for this. In fact the year that people are born shouldn't be taken into consideration, for simplicity.
The basic question is given an input, a single integer representing the number of people in the room (X >= 1). Return the probability that 2 or more people share the same birthday.
The return from the function should be a value between 0 and 1, inclusive. It should also be rounded out to the 10 thousandth decimal point (4 after the decimal point). There should be no trailing zeros included.
Solution Stats
Problem Comments
-
6 Comments
I think there might be something wrong with the test suite. When I run in Matlab, my answers match what the test suite is looking for, yet it still shows a failure.
Ben, your description suggests that rounding to 4 decimal places is optional. Perhaps you can clarify that. Test case with x = 365 is weird. The probability that no one shares a birthday for that x is close to 1.4550e-157 which is neglected during the rounding and hence highly probable event becomes a certainty !!
@Gary What you might be seeing is that the default output from Matlab is only 5 digits (generally). So you're probably seeing something like 0.0027 for X = 2 but if you multiply that answer by 1000 you will see there are still some digits trailing after the 7.
@Venu I think that's just an issue with how I did the calculation on my end. You're right that I should have it as 0.9999 in the test suite even though that is super close to 1 (the actual probability). I'll also make it clear in the brief that the answer should be out to 4 decimal points.
The problem should state truncate at the 10 thousandth point. n=50 is .97037 so the correct rounded answer is .9704 not .9703.
Instruction is to round, but correct answers are truncated (.9703 vs .9704)
I've used the function floor instead of round, because of the issue mentioned above and it worked.
Solution Comments
Show commentsProblem Recent Solvers204
Suggested Problems
-
Set some matrix elements to zero
536 Solvers
-
1031 Solvers
-
500 Solvers
-
Find out sum and carry of Binary adder
1482 Solvers
-
Calculate Amount of Cake Frosting
24943 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!