Cody

Solution 1294680

Submitted on 18 Oct 2017 by @bmtran (Bryant Tran)
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

This solution is outdated. To rescore this solution, sign in.

Test Suite

Test Status Code Input and Output
1   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]))

siz = 4 4

2   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]))

siz = 4 4

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

siz = 4 4

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

siz = 4 4