Skip to "Task" if you are familiar with Tic-Tac-Toe (I think most are!)
Tic-Tac-Toe is a famous two-player game. It consists of a 3x3 board that is filled gradually by two players (clarifications below); The first player uses the character
X and the other one uses
O. The winner is the first to get 3 consecutive and identical characters (
O), either horizontally, vertically or diagonally. In case the board is filled and none of the players managed to get three consecutive characters as decribed above, the game ends in a tie. Note that there might be empty spots at the end of the game, in case either of the players wins in less than 9 moves in total (this cannot happen in case of a tie).
Given a Tic-Tac-Toe board at the end of a game (in the form of a string, a matrix, a flat list of 9 ordered values, any other decent format), determine who wins the game.
The input will consist of distinct and consistent values, one for
X, one for
Oand another one that represents an empty spot.
Your program should be able to output 3 distinct, consistent and non-empty values: one in case
Xwins, another one in case
Owins or another if the players are tied.
Please specify these values in your answer. You can assume that the input will be a valid Tic-Tac-Toe board.
_ are the input values here;
O wins and
Tie are for the output.
X O X O X _ O _ X
X _ O X O _ X O X
X O X _ O X _ O _
X O X O O X X X O
As usual, all our standard rules apply. This is code-golf, the shortest code in bytes in every language wins!