Cody

Solution 1938432

Submitted on 16 Sep 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
filetext = fileread('sliding.m'); assert(isempty(strfind(filetext,'6 10 14 15 16'))) assert(isempty(strfind(filetext,'6,10,14,15,16')))

2   Fail
p = [1 2 3 4;5 10 6 7;9 0 11 8;13 14 15 12]; m = sliding(p); for i = 1:numel(m) if round(m(i)) == m(i) && m(i) <= numel(p) && m(i) > 0 zero = find(p == 0); [rzero czero] = ind2sub(size(p),zero); [rmove cmove] = ind2sub(size(p),m(i)); if abs(rzero + czero - rmove - cmove) == 1 p([m(i) zero]) = p([zero m(i)]); end end end assert(isequal(p,[1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 0]))

p = 1 5 9 13 2 10 0 14 3 6 11 15 4 7 8 12 ans = 0 0 0 0 0 4 -10 0 0 -1 0 0 0 -1 -4 NaN l = 6 7 8 10 12 16 ans = 7

Output argument "m" (and maybe others) not assigned during call to "sliding". Error in Test2 (line 2) m = sliding(p);

3   Fail
p = [6 3 0 11;7 14 8 5;15 1 2 4;13 9 10 12]; m = sliding(p); for i = 1:numel(m) if round(m(i)) == m(i) && m(i) <= numel(p) && m(i) > 0 zero = find(p == 0); [rzero czero] = ind2sub(size(p),zero); [rmove cmove] = ind2sub(size(p),m(i)); if abs(rzero + czero - rmove - cmove) == 1 p([m(i) zero]) = p([zero m(i)]); end end end assert(isequal(p,[1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 0]))

p = 6 7 15 13 3 14 1 9 0 8 2 10 11 5 4 12 ans = 5 2 6 0 1 8 -9 -5 -3 1 -9 -5 7 -3 -8 NaN l = 1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 ans = 10

Output argument "m" (and maybe others) not assigned during call to "sliding". Error in Test3 (line 2) m = sliding(p);

4   Fail
p = [8 2 3 13;1 6 10 9;15 14 0 5;11 12 4 7]; m = sliding(p); for i = 1:numel(m) if round(m(i)) == m(i) && m(i) <= numel(p) && m(i) > 0 zero = find(p == 0); [rzero czero] = ind2sub(size(p),zero); [rmove cmove] = ind2sub(size(p),m(i)); if abs(rzero + czero - rmove - cmove) == 1 p([m(i) zero]) = p([zero m(i)]); end end end assert(isequal(p,[1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 0]))

p = 8 1 15 11 2 6 14 12 3 10 0 4 13 9 5 7 ans = 7 -4 6 -2 0 0 4 -2 0 3 -11 -11 9 1 -7 NaN l = 1 4 5 7 8 9 10 11 12 13 14 15 16 ans = 5

Output argument "m" (and maybe others) not assigned during call to "sliding". Error in Test4 (line 2) m = sliding(p);

5   Fail
p = [11 7 15 9;3 1 0 8;5 12 13 4;14 2 10 6]; m = sliding(p); for i = 1:numel(m) if round(m(i)) == m(i) && m(i) <= numel(p) && m(i) > 0 zero = find(p == 0); [rzero czero] = ind2sub(size(p),zero); [rmove cmove] = ind2sub(size(p),m(i)); if abs(rzero + czero - rmove - cmove) == 1 p([m(i) zero]) = p([zero m(i)]); end end end assert(isequal(p,[1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 0]))

p = 11 3 5 14 7 1 12 2 15 0 13 10 9 8 4 6 ans = 10 -2 -4 1 5 -5 2 -12 12 -7 2 -5 5 0 -8 NaN l = 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 ans = 6

Output argument "m" (and maybe others) not assigned during call to "sliding". Error in Test5 (line 2) m = sliding(p);