Cody

Problem 1272. The almost-birthday problem.

Solution 2756929

Submitted on 29 Jul 2020 by Dennis Gimlin
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
n = 10; d = 1; y_correct = 0.3147; assert(abs(almostBirthday(n,d)-y_correct) <= 0.0001)

p = 0.3147 yMax = 0.4754 ans = 0.5105

2   Pass
n = 14; d = 1; y_correct = 0.5375; assert(abs(almostBirthday(n,d)-y_correct) <= 0.0001)

p = 0.5375 yMax = 0.7359 ans = 0.3691

3   Pass
n = 20; d = 1; y_correct = 0.8045; assert(abs(almostBirthday(n,d)-y_correct) <= 0.0001)

p = 0.8045 yMax = 0.9434 ans = 0.1727

4   Pass
n = 25; d = 1; y_correct = 0.9263; assert(abs(almostBirthday(n,d)-y_correct) <= 0.0001)

p = 0.9263 yMax = 0.9906 ans = 0.0695

5   Pass
n = 30; d = 1; y_correct = 0.9782; assert(abs(almostBirthday(n,d)-y_correct) <= 0.0001)

p = 0.9782 yMax = 0.9991 ans = 0.0213

6   Pass
n = 35; d = 1; y_correct = 0.9950; assert(abs(almostBirthday(n,d)-y_correct) <= 0.0001)

p = 0.9950 yMax = 0.9999 ans = 0.0050

7   Pass
n = 10; d = 2; y_correct = 0.4721; assert(abs(almostBirthday(n,d)-y_correct) <= 0.0001)

p = 0.4721 yMax = 0.6018 ans = 0.2747

8   Pass
n = 14; d = 2; y_correct = 0.7305; assert(abs(almostBirthday(n,d)-y_correct) <= 0.0001)

p = 0.7305 yMax = 0.8532 ans = 0.1680

9   Pass
n = 20; d = 2; y_correct = 0.9393; assert(abs(almostBirthday(n,d)-y_correct) <= 0.0001)

p = 0.9393 yMax = 0.9851 ans = 0.0488

10   Pass
n = 25; d = 2; y_correct = 0.9890; assert(abs(almostBirthday(n,d)-y_correct) <= 0.0001)

p = 0.9890 yMax = 0.9990 ans = 0.0101

11   Pass
n = 30; d = 2; y_correct = 0.9987; assert(abs(almostBirthday(n,d)-y_correct) <= 0.0001)

p = 0.9987 yMax = 1.0000 ans = 0.0012

12   Pass
n = 10; d = 3; y_correct = 0.5965; assert(abs(almostBirthday(n,d)-y_correct) <= 0.0001)

p = 0.5965 yMax = 0.7012 ans = 0.1756

13   Pass
n = 14; d = 3; y_correct = 0.8466; assert(abs(almostBirthday(n,d)-y_correct) <= 0.0001)

p = 0.8466 yMax = 0.9215 ans = 0.0884

14   Pass
n = 20; d = 3; y_correct = 0.9826; assert(abs(almostBirthday(n,d)-y_correct) <= 0.0001)

p = 0.9826 yMax = 0.9966 ans = 0.0143

15   Pass
n = 25; d = 3; y_correct = 0.9986; assert(abs(almostBirthday(n,d)-y_correct) <= 0.0001)

p = 0.9986 yMax = 0.9999 ans = 0.0013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!