Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 172127

Submitted on 4 Dec 2012 by Vitaly Lavrukhin

Correct

30Size
Leading solution size is 17.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
n = 20;
r = 3;
filetext = fileread('mag_rang.m');
assert(isequal(mag_rang(n),r))
assert(isempty(strfind(filetext, 'rank')))
assert(isempty(strfind(filetext, 'magic')))
ans =
     3
2
Pass
 
%%
n = 4;
r = 3;
filetext = fileread('mag_rang.m');
assert(isequal(mag_rang(n),r))
assert(isempty(strfind(filetext, 'rank')))
assert(isempty(strfind(filetext, 'magic')))
ans =
     3
3
Pass
 
%%
n = 15;
r = 15;
filetext = fileread('mag_rang.m');
assert(isequal(mag_rang(n),r))
assert(isempty(strfind(filetext, 'rank')))
assert(isempty(strfind(filetext, 'magic')))
n =
    15
4
Pass
 
%%
n = 18;
r = 11;
filetext = fileread('mag_rang.m');
assert(isequal(mag_rang(n),r))
assert(isempty(strfind(filetext, 'rank')))
assert(isempty(strfind(filetext, 'magic')))
ans =
    11
5
Pass
 
%%
n = 16;
r = 3;
filetext = fileread('mag_rang.m');
assert(isequal(mag_rang(n),r))
assert(isempty(strfind(filetext, 'rank')))
assert(isempty(strfind(filetext, 'magic')))
ans =
     3
6
Pass
 
%%
n = 170;
r = 87;
filetext = fileread('mag_rang.m');
assert(isequal(mag_rang(n),r))
assert(isempty(strfind(filetext, 'rank')))
assert(isempty(strfind(filetext, 'magic')))
ans =
    87
7
Pass
 
%%
n = 112;
r = 3;
filetext = fileread('mag_rang.m');
assert(isequal(mag_rang(n),r))
assert(isempty(strfind(filetext, 'rank')))
assert(isempty(strfind(filetext, 'magic')))
ans =
     3
8
Pass
 
%%
n = 170;
r = 87;
filetext = fileread('mag_rang.m');
assert(isequal(mag_rang(n),r))
assert(isempty(strfind(filetext, 'rank')))
assert(isempty(strfind(filetext, 'magic')))
ans =
    87