Evaluating a Tic-tac-toe game

Question

Given a 3x3 matrix of a completed tic-tac-toe game, create a function that returns the winner of the game. If there is no winner, the function should output "Draw". Below are some example matrices (games) and their expected output.

   
# Example 1:
input = [['O', 'X', 'X'],
         ['X', 'X', 'O'],
         ['O', 'X', 'O']]
output = X
 
# Example 2:
input = [['O', 'X', 'X'],
         ['X', 'O', 'O'],
         ['O', 'X', 'O']]
output = O
 
# Example 3:
input = [['O', 'X', 'X'],
         ['X', 'O', 'O'],
         ['O', 'X', 'X']]
output = Draw

Solution

Access restricted

Subscribe to premium account to see the solution.

Get premium now