Problem 2346. Tic Tac Toe Solver

Create a function that checks n number of tic tac toe boards housed in a 3x3xn matrix where the x's are represented as 1's (and o's as 0's) to determine which player won (if either) and which direction the win lies. 1=win for x's, 0=win for o's, -1=tie. 1=horizontal, 2=vertical, 3=diagonal, 0=not applicable (used for a tie). For example, in the following board:

 0 1 0
 1 1 1
 1 0 0

the 1's player won in a horizontal direction: [1 1].

See the test suite below for more examples. The solution will be an nx2 matrix with one row for each board.

Solution Stats

78.57% Correct | 21.43% Incorrect
Last solution submitted on Feb 13, 2016

Problem Comments

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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!