Cody

# Problem 96. Knight's Tour Checker

Solution 1859900

Submitted on 27 Jun 2019 by James Browne
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
a = ... [ 7 2 5 4 0 8 1 6 3]; tf_correct = true; assert(isequal(knights_tour(a),tf_correct))

y = 3 x = 1 y = 3 1 x = 1 2 y = 3 1 3 x = 1 2 3 y = 3 1 3 2 x = 1 2 3 1 y = 3 1 3 2 1 x = 1 2 3 1 3 y = 3 1 3 2 1 3 x = 1 2 3 1 3 2 y = 3 1 3 2 1 3 1 x = 1 2 3 1 3 2 1 y = 3 1 3 2 1 3 1 2 x = 1 2 3 1 3 2 1 3

2   Pass
a = ... [ 1 0 0 0 0 2]; tf_correct = true; assert(isequal(knights_tour(a),tf_correct))

y = 1 x = 1 y = 1 2 x = 1 3

3   Pass
a = ... [ 15 5 12 3 0 2 9 6 8 11 4 13 1 14 7 10]; tf_correct = false; assert(isequal(knights_tour(a),tf_correct))

y = 4 x = 1 y = 4 2 x = 1 2 y = 4 2 1 x = 1 2 4 y = 4 2 1 3 x = 1 2 4 3 y = 4 2 1 3 1 x = 1 2 4 3 2 y = 4 2 1 3 1 2 x = 1 2 4 3 2 4 y = 4 2 1 3 1 2 4 x = 1 2 4 3 2 4 3 y = 4 2 1 3 1 2 4 3 x = 1 2 4 3 2 4 3 1 y = 4 2 1 3 1 2 4 3 2 x = 1 2 4 3 2 4 3 1 3 y = 4 2 1 3 1 2 4 3 2 4 x = 1 2 4 3 2 4 3 1 3 4 y = 4 2 1 3 1 2 4 3 2 4 3 x = 1 2 4 3 2 4 3 1 3 4 2 y = 4 2 1 3 1 2 4 3 2 4 3 1 x = 1 2 4 3 2 4 3 1 3 4 2 3 y = 4 2 1 3 1 2 4 3 2 4 3 1 3 x = 1 2 4 3 2 4 3 1 3 4 2 3 4 y = 4 2 1 3 1 2 4 3 2 4 3 1 3 4 x = 1 2 4 3 2 4 3 1 3 4 2 3 4 2 y = 4 2 1 3 1 2 4 3 2 4 3 1 3 4 1 x = 1 2 4 3 2 4 3 1 3 4 2 3 4 2 1

4   Pass
a = ... [ 0 5 12 3 15 2 9 6 8 11 4 13 1 14 7 10]; tf_correct = true; assert(isequal(knights_tour(a),tf_correct))

y = 4 x = 1 y = 4 2 x = 1 2 y = 4 2 1 x = 1 2 4 y = 4 2 1 3 x = 1 2 4 3 y = 4 2 1 3 1 x = 1 2 4 3 2 y = 4 2 1 3 1 2 x = 1 2 4 3 2 4 y = 4 2 1 3 1 2 4 x = 1 2 4 3 2 4 3 y = 4 2 1 3 1 2 4 3 x = 1 2 4 3 2 4 3 1 y = 4 2 1 3 1 2 4 3 2 x = 1 2 4 3 2 4 3 1 3 y = 4 2 1 3 1 2 4 3 2 4 x = 1 2 4 3 2 4 3 1 3 4 y = 4 2 1 3 1 2 4 3 2 4 3 x = 1 2 4 3 2 4 3 1 3 4 2 y = 4 2 1 3 1 2 4 3 2 4 3 1 x = 1 2 4 3 2 4 3 1 3 4 2 3 y = 4 2 1 3 1 2 4 3 2 4 3 1 3 x = 1 2 4 3 2 4 3 1 3 4 2 3 4 y = 4 2 1 3 1 2 4 3 2 4 3 1 3 4 x = 1 2 4 3 2 4 3 1 3 4 2 3 4 2 y = 4 2 1 3 1 2 4 3 2 4 3 1 3 4 2 x = 1 2 4 3 2 4 3 1 3 4 2 3 4 2 1

5   Pass
a = [22 29 4 31 16 35;3 32 23 34 5 14;28 21 30 15 36 17;9 2 33 24 13 6;20 27 8 11 18 25;1 10 19 26 7 12]; tf_correct = true; assert(isequal(knights_tour(a),tf_correct))

y = 6 x = 1 y = 6 4 x = 1 2 y = 6 4 2 x = 1 2 1 y = 6 4 2 1 x = 1 2 1 3 y = 6 4 2 1 2 x = 1 2 1 3 5 y = 6 4 2 1 2 4 x = 1 2 1 3 5 6 y = 6 4 2 1 2 4 6 x = 1 2 1 3 5 6 5 y = 6 4 2 1 2 4 6 5 x = 1 2 1 3 5 6 5 3 y = 6 4 2 1 2 4 6 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 5 6 5 3 1 3 Columns 31 through 32 1 2 x = Columns 1 through 30 1 2 1 3 5 6 5 3 1 2 4 6 5 6 4 5 6 5 3 1 2 1 3 4 6 4 2 1 2 3 Columns 31 through 32 4 2 y = Columns 1 through 30 6 4 2 1 2 4 6 5 4 6 5 6 4 2 3 1 3 5 6 5 3 1 2 4 5 6 5 3 1 3 Columns 31 through 33 1 2 4 x = Columns 1 through 30 1 2 1 3 5 6 5 3 1 2 4 6 5 6 4 5 6 5 3 1 2 1 3 4 6 4 2 1 2 3 Columns 31 through 33 4 2 3 y = Columns 1 through 30 6 4 2 1 2 4 6 5 4 6 5 6 4 2 3 1 3 5 6 5 3 1 2 4 5 6 5 3 1 3 Columns 31 through 34 1 2 4 2 x = Columns 1 through 30 1 2 1 3 5 6 5 3 1 2 4 6 5 6 4 5 6 5 3 1 2 1 3 4 6 4 2 1 2 3 Columns 31 through 34 4 2 3 4 y = Columns 1 through 30 6 4 2 1 2 4 6 5 4 6 5 6 4 2 3 1 3 5 6 5 3 1 2 4 5 6 5 3 1 3 Columns 31 through 35 1 2 4 2 1 x = Columns 1 through 30 1 2 1 3 5 6 5 3 1 2 4 6 5 6 4 5 6 5 3 1 2 1 3 4 6 4 2 1 2 3 Columns 31 through 35 4 2 3 4 6 y = Columns 1 through 30 6 4 2 1 2 4 6 5 4 6 5 6 4 2 3 1 3 5 6 5 3 1 2 4 5 6 5 3 1 3 Columns 31 through 36 1 2 4 2 1 3 x = Columns 1 through 30 1 2 1 3 5 6 5 3 1 2 4 6 5 6 4 5 6 5 3 1 2 1 3 4 6 4 2 1 2 3 Columns 31 through 36 4 2 3 4 6 5

6   Pass
a = [22 29 4 31 16 35;3 32 23 34 5 14;28 21 30 15 0 17;2 9 33 24 13 6;20 27 8 11 18 25;1 10 19 26 7 12]; tf_correct = false; assert(isequal(knights_tour(a),tf_correct))

y = 6 x = 1 y = 6 4 x = 1 1 y = 6 4 2 x = 1 1 1 y = 6 4 2 1 x = 1 1 1 3 y = 6 4 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x = Columns 1 through 30 1 1 1 3 5 6 5 3 2 2 4 6 5 6 4 5 6 5 3 1 2 1 3 4 6 4 2 1 2 3 Column 31 4 y = Columns 1 through 30 6 4 2 1 2 4 6 5 4 6 5 6 4 2 3 1 3 5 6 5 3 1 2 4 5 6 5 3 1 3 Columns 31 through 32 1 2 x = Columns 1 through 30 1 1 1 3 5 6 5 3 2 2 4 6 5 6 4 5 6 5 3 1 2 1 3 4 6 4 2 1 2 3 Columns 31 through 32 4 2 y = Columns 1 through 30 6 4 2 1 2 4 6 5 4 6 5 6 4 2 3 1 3 5 6 5 3 1 2 4 5 6 5 3 1 3 Columns 31 through 33 1 2 4 x = Columns 1 through 30 1 1 1 3 5 6 5 3 2 2 4 6 5 6 4 5 6 5 3 1 2 1 3 4 6 4 2 1 2 3 Columns 31 through 33 4 2 3 y = Columns 1 through 30 6 4 2 1 2 4 6 5 4 6 5 6 4 2 3 1 3 5 6 5 3 1 2 4 5 6 5 3 1 3 Columns 31 through 34 1 2 4 2 x = Columns 1 through 30 1 1 1 3 5 6 5 3 2 2 4 6 5 6 4 5 6 5 3 1 2 1 3 4 6 4 2 1 2 3 Columns 31 through 34 4 2 3 4 y = Columns 1 through 30 6 4 2 1 2 4 6 5 4 6 5 6 4 2 3 1 3 5 6 5 3 1 2 4 5 6 5 3 1 3 Columns 31 through 35 1 2 4 2 1 x = Columns 1 through 30 1 1 1 3 5 6 5 3 2 2 4 6 5 6 4 5 6 5 3 1 2 1 3 4 6 4 2 1 2 3 Columns 31 through 35 4 2 3 4 6

7   Pass
a = [1 0 0;0 0 0;2 0 0]; tf_correct = false; assert(isequal(knights_tour(a),tf_correct))

y = 1 x = 1 y = 1 3 x = 1 1