Cody

Solution 1735902

Submitted on 25 Feb 2019 by Jean-Marie Sainthillier
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   Pass
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]))

3   Pass
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]))

4   Pass
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]))

5   Pass
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]))