It seems to me that this solution unintentionally messed up its last code line and got lucky with the test suite, because this solution would not correctly identify x = [1,0,0; 0,0,0; 0,0,0] or x = [1,1,1; 1,1,0; 1,0,0] as valid TicTacToe states. Unless your very purpose was to actually expose/exploit this "shortcoming" in the test suite, of course! :)
Thanks for your comment. I was confused by the original problem description such as "state 0: legal 1: this state", where the extra colons seem to be misleading. After some digging, I have figured out the rationale of TicTacToe, and thus, updated my solutions.
Thanks for your reply, Peng Liu. I'll admit, I too was (and still am) confused by the "state 0: legal 1: this state" sentence in the problem description. Luckily I was already familiar with the TicTacToe game.
Hi, yurenchu & Peng Liu. I agree the punctuation and syntax are very confusing, and indeed misleading. As written it seems to define 0 as representing legal states — which, besides being unusual (although possible), is contrary to the Test Suite and the example above. A clearer way to state the sentence may be: "For this challenge please categorise the given board state as either 1 = legal state, or 0 = illegal state (cannot occur in a game)."
Test  Status  Code Input and Output 

1  Pass 
x = [1 1 0
0 0 0
0 0 0];
y_correct = 0;
assert(isequal(isLegalTicTacToeState(x),y_correct))
ans =
logical
0

2  Pass 
x = [0 0 0
0 0 0
0 0 0];
y_correct = 1;
assert(isequal(isLegalTicTacToeState(x),y_correct))
ans =
logical
1

3  Pass 
x = [ 1 1 1
1 1 1
1 1 1];
y_correct = 0;
assert(isequal(isLegalTicTacToeState(x),y_correct))
ans =
logical
0

4  Pass 
x = [ 0 1 1
1 1 0
1 0 0];
y_correct = 1;
assert(isequal(isLegalTicTacToeState(x),y_correct))
ans =
logical
1

5  Pass 
x = [ 1 1 1
1 1 1
0 0 0];
y_correct = 0;
assert(isequal(isLegalTicTacToeState(x),y_correct))
ans =
logical
0

6  Pass 
x = [1 1 1
0 1 1
1 0 1];
y_correct = 0;
assert(isequal(isLegalTicTacToeState(x),y_correct))
ans =
logical
0

7  Pass 
x = [1 1 0
0 0 0
0 0 0];
y_correct = 1;
assert(isequal(isLegalTicTacToeState(x),y_correct))
ans =
logical
1

8  Pass 
x = [1 0 0
0 0 0
0 0 0];
y_correct = 0;
assert(isequal(isLegalTicTacToeState(x),y_correct))
ans =
logical
0

9  Pass 
x = [1 1 0
0 1 0
0 1 0];
y_correct = 0;
assert(isequal(isLegalTicTacToeState(x),y_correct))
ans =
logical
0

10  Pass 
x = [1 1 1
1 1 1
1 1 1];
y_correct = 1;
assert(isequal(isLegalTicTacToeState(x),y_correct))
ans =
logical
1

How to find the position of an element in a vector without using the find function
2436 Solvers
389 Solvers
Convert from Base 10 to base 5
189 Solvers
Determine the number of odd integers in a vector
400 Solvers
169 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!