Cody

# Problem 42842. The sliding puzzle: 15

Solution 1583197

Submitted on 14 Jul 2018 by Are Mjaavatten
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
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]))

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

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

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