Let's play some code-golf!
The challenge is to find the winner of a game of Tic-Tac-Toe.
This has been done many times by giving a board that has one clear winner but here is the twist:
The cells are numbered like this:
1|2|3
-+-+-
4|5|6
-+-+-
7|8|9
You get an array of exactly 9 moves like that:
{3, 5, 6, 7, 9, 8, 1, 2, 3}
This is parsed as follows:
- Player 1 marks cell 3
- Player 2 marks cell 5
- Player 1 marks cell 6
- Player 2 marks cell 7
- Player 1 marks cell 9
- Player 1 has won
Note: The game does not stop after one player has won, it may happen that the losing player manages to get three in a row after the winning player, but only the first win counts.
Your job is now to get 9 numbers as input and output the winning player and the round in which the win occured. If no one wins, output something constant of your choice. You can receive input and provide output through any standard mean / format.
Have fun!
Some more examples as requested:
{2,3,4,5,6,7,1,8,9} => Player 2 wins in round 6
{1,2,4,5,6,7,3,8,9} => Player 2 wins in round 8
{1,2,3,5,4,7,6,8,9} => Player 2 wins in round 8
[X, Y]
? In case of a tie, can we output any other consistent value instead? I recommend so, because printing those exact strings aren't really part of golfing. For future challenge ideas, I recommend using the sandbox. :-) \$\endgroup\${3, 5, 6, 7, 9, 8, 1, 2, 3}
" - should3
really appear twice? \$\endgroup\$