Cody

# Problem 44503. Anyone for tennis? Your chances of winning a tie-break game

Solution 3451463

Submitted on 28 Oct 2020 by Nicolas Schoonbroodt
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
% The Test Suite will be updated if inappropriate submissions are received. % This includes hard-coded (pre-calculated, externally calculated, manually calculated) 'solutions'. % EDIT (2019-06-24). Anti-hacking provision % Ensure builtin function will be called. (Probably only the second of these will work.) ! del fileread.m ! rm -v fileread.m % Disallow certain words RE = regexp(fileread('tiebreakGame.m'), '\w+', 'match'); tabooWords = {'ans', 'assert', 'freepass'}; testResult = cellfun( @(z) ismember(z, tabooWords), RE ); msg = ['Please do not do that in your code!' char([10 13]) ... 'Found: ' strjoin(RE(testResult)) '.' char([10 13]) ... 'Banned word.' char([10 13])]; assert(~any( cellfun( @(z) ismember(z, tabooWords), RE ) ), msg) % END EDIT (2019-06-24) filetext = fileread('tiebreakGame.m'); vec = [5242178 5616877 7920095 4815022 1826772 5089792,5089793 1134259 2125443 3458492 4684486]; msg = 'Please do not hard-code your ''solution''.'; assert( all( arrayfun(@(z) isempty(strfind(filetext, num2str(z))), vec) ) , msg )

2   Pass
% There are only two players, so the chances for each should add up to one. assert( abs(tiebreakGame(100)+tiebreakGame(0) - 1) < 20 * eps(single(1)) ) assert( abs(tiebreakGame(90)+tiebreakGame(10) - 1) < 20 * eps(single(1)) ) assert( abs(tiebreakGame(80)+tiebreakGame(20) - 1) < 20 * eps(single(1)) ) assert( abs(tiebreakGame(70)+tiebreakGame(30) - 1) < 20 * eps(single(1)) ) assert( abs(tiebreakGame(60)+tiebreakGame(40) - 1) < 20 * eps(single(1)) ) assert( abs(tiebreakGame(50)+tiebreakGame(50) - 1) < 20 * eps(single(1)) )

chance = single 1 chance = single 0 chance = single 0.9999 chance = single 5.6169e-05 chance = single 0.9952 chance = single 0.0048 chance = single 0.9491 chance = single 0.0509 chance = single 0.7875 chance = single 0.2125 chance = single 0.5000 chance = single 0.5000

`  `
`  `
`  `
`  `
`  `
`  `
`  `
`  `
`  `
`  `
3   Pass
x = uint8(50); y_correct = 0.50; assert( isequal(tiebreakGame(x), y_correct) )

chance = single 0.5000

4   Pass
x = uint8(0); y_correct = 0; assert( isequal(tiebreakGame(x), y_correct) )

chance = single 0

5   Pass
x = uint8(100); y_correct = 1; assert( isequal(tiebreakGame(x), y_correct) )

chance = single 1

6   Pass
x = uint8(5); y_correct = 0.0000005242178465; assert( abs( tiebreakGame(x) - y_correct ) < 10 * eps(single(y_correct)) )

chance = single 5.2422e-07

7   Pass
x = uint8(10); y_correct = 0.0000561687707317; assert( abs( tiebreakGame(x) - y_correct ) < 10 * eps(single(y_correct)) )

chance = single 5.6169e-05

8   Pass
x = uint8(15); y_correct = 0.0007920095157735; assert( abs( tiebreakGame(x) - y_correct ) < 10 * eps(single(y_correct)) )

chance = single 7.9201e-04

9   Pass
x = uint8(20); y_correct = 0.0048150226823529; assert( abs( tiebreakGame(x) - y_correct ) < 10 * eps(single(y_correct)) )

chance = single 0.0048

10   Pass
x = uint8(25); y_correct = 0.0182677268981934; assert( abs( tiebreakGame(x) - y_correct ) < 10 * eps(single(y_correct)) )

chance = single 0.0183

11   Pass
x = uint8(30); y_correct = 0.0508979303379310; assert( abs( tiebreakGame(x) - y_correct ) < 10 * eps(single(y_correct)) )

chance = single 0.0509

12   Pass
x = uint8(35); y_correct = 0.1134259300865006; assert( abs( tiebreakGame(x) - y_correct ) < 10 * eps(single(y_correct)) )

chance = single 0.1134

13   Pass
x = uint8(40); y_correct = 0.2125443387076924; assert( abs( tiebreakGame(x) - y_correct ) < 10 * eps(single(y_correct)) )

chance = single 0.2125

14   Pass
x = uint8(45); y_correct = 0.3458492328206313; assert( abs( tiebreakGame(x) - y_correct ) < 10 * eps(single(y_correct)) )

chance = single 0.3458

15   Pass
x = uint8(49); y_correct = 0.4684486239083455; assert( abs( tiebreakGame(x) - y_correct ) < 10 * eps(single(y_correct)) )

chance = single 0.4684

16   Pass
for i = 1:5 x = uint8( randi(100) ); assert( isequal(class(tiebreakGame(x)), 'single') ) end;

chance = single 0.0718 chance = single 0.0509 chance = single 0.9982 chance = single 1.8673e-04 chance = single 0.9019

### Community Treasure Hunt

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

Start Hunting!