Cody

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

Solution 1734799

Submitted on 24 Feb 2019 by William
• Size: 84
• This is the leading solution.
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)) )

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

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

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

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

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

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

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

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

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

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

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

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

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

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

### Community Treasure Hunt

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

Start Hunting!