Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 450554

Submitted on 5 Jun 2014 by Ned Gulley

Correct

135Size
Leading solution size is 29.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
board = [1 0 0;
	 0 1 0;
	 1 0 1];
win_ans = [1 3];
assert(isequal(ttt_checker(board),win_ans))

                    
2
Pass
 
%%
board = [1 0 1;
	 0 1 0;
	 0 1 0];
win_ans = [-1 0];
assert(isequal(ttt_checker(board),win_ans))

                    
3
Pass
 
%%
board = zeros(3,3,2);
win_ans = zeros(2,2);
board(:,:,1) = [0 1 0;
		1 1 1;
		1 0 0];
win_ans(1,:) = [1 1];
board(:,:,2) = [0 0 0;
		1 1 0;
		0 1 1];
win_ans(2,:) = [0 1];
assert(isequal(ttt_checker(board),win_ans))

                    
4
Pass
 
%%
board = zeros(3,3,4);
win_ans = zeros(4,2);
board(:,:,1) = [1 0 1;
		0 1 1;
		0 1 0];
win_ans(1,:) = [-1 0];
board(:,:,2) = [0 0 1;
		0 1 0;
		0 1 1];
win_ans(2,:) = [0 2];
board(:,:,3) = [1 1 1;
		1 0 0;
		0 1 0];
win_ans(3,:) = [1 1];
board(:,:,4) = [1 0 1;
		0 0 0;
		0 1 1];
win_ans(4,:) = [0 1];
assert(isequal(ttt_checker(board),win_ans))

                    
5
Pass
 
%%
board = zeros(3,3,5);
win_ans = zeros(5,2);
board(:,:,1) = [1 1 0;
		0 0 1;
		0 1 0];
win_ans(1,:) = [0 3];
board(:,:,2) = [0 0 1;
		1 1 0;
		0 1 1];
win_ans(2,:) = [-1 0];
board(:,:,3) = [1 1 0;
		0 1 1;
		0 1 0];
win_ans(3,:) = [1 2];
board(:,:,4) = [1 0 1;
		1 0 0;
		0 0 1];
win_ans(4,:) = [0 2];
board(:,:,5) = [1 0 1;
		0 1 0;
		0 1 1];
win_ans(5,:) = [1 3];
assert(isequal(ttt_checker(board),win_ans))