Cody

# Problem 44692. Is input the global variable z?

Solution 1721132

Submitted on 5 Feb 2019
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
% This Test Suite can be updated if inappropriate 'hacks' are discovered % in any submitted solutions, so your submission's status may therefore change over time. assessFunctionAbsence({'regexp', 'regexpi'}, 'FileName','checkInput.m') RE = regexp(fileread('checkInput.m'), '\w+', 'match'); tabooWords = {'ans'}; 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( testResult ), msg)

2   Pass
global z x = 3; y = 2; z = 1; assert( checkInput(z) ) assert( ~checkInput(x) ) assert( ~checkInput(y) )

inName = 'z' inName = 'x' inName = 'y'

3   Pass
global z x = 1; y = 2; z = 3; assert( checkInput(z) ) assert( ~checkInput(x) ) assert( ~checkInput(y) )

inName = 'z' inName = 'x' inName = 'y'

4   Pass
global z x = 3; y = 1; z = 2; assert( checkInput(z) ) assert( ~checkInput(x) ) assert( ~checkInput(y) )

inName = 'z' inName = 'x' inName = 'y'

5   Pass
global z z = 2; assert( checkInput(z) ) assert( ~checkInput(1) ) assert( ~checkInput(3) )

inName = 'z' inName = 0×0 empty char array inName = 0×0 empty char array

6   Pass
global z z = 1; assert( checkInput(z) ) assert( ~checkInput(2) ) assert( ~checkInput(3) )

inName = 'z' inName = 0×0 empty char array inName = 0×0 empty char array

7   Pass
global z z = 3; assert( checkInput(z) ) assert( ~checkInput(1) ) assert( ~checkInput(2) )

inName = 'z' inName = 0×0 empty char array inName = 0×0 empty char array

8   Pass
global x y z x = 3; y = 1; z = 2; assert( checkInput(z) ) assert( ~checkInput(x) ) assert( ~checkInput(y) )

inName = 'z' inName = 'x' inName = 'y'

9   Pass
global x y z x = 2; y = 1; z = 3; assert( checkInput(z) ) assert( ~checkInput(x) ) assert( ~checkInput(y) )

inName = 'z' inName = 'x' inName = 'y'

10   Fail
global x y z x = 2; z = 3; testX = @(x) checkInput(x); testZ = @(z) checkInput(z); assert( ~testX(x) ) assert( ~testZ(x) ) assert( testX(z) ) assert( testZ(z) )

inName = 'x' inName = 'z'

Assertion failed.

11   Fail
global x y z x = 3; z = 2; testX = @(x) checkInput(x); testZ = @(z) checkInput(z); assert( ~testX(x) ) assert( ~testZ(x) ) assert( testX(z) ) assert( testZ(z) )

inName = 'x' inName = 'z'

Assertion failed.

12   Fail
clear global x = 1; y = 2; z = 3; assert( ~checkInput(z) ) assert( ~checkInput(x) ) assert( ~checkInput(y) )

inName = 'z'

Assertion failed.

13   Fail
clear global x = 3; y = 2; z = 1; assert( ~checkInput(z) ) assert( ~checkInput(x) ) assert( ~checkInput(y) )

inName = 'z'

Assertion failed.