46 Tic-Tac-Toe Problem statement

Back to Problem Solutions forum

Cl3r1k     2016-12-12 06:54:15
User avatar

Can someone clarify what exactly should contains answer on this problem.

As described in task "Answer should contain the number of the move at which game is won by one of players (starting from 1) or 0 if the game is drawn (no winner) after the last move." But my answer does not similar with answer wich gives the site.

For example we have test-case 9 numbers(took from provided list) - 3 1 2 5 8 6 7 4 9 and answer should be 8 (the answer gives the site)

In my thought it should be 4. That is how i found it:

X O

3 1 2 5 8 6 7 4 --- O strike the line (4, 5, 6) 9

Which leads to the following position: O | X | X ---+---+--- O | O | O --- O strike the line (4, 5, 6) ---+---+--- X | X |

It means that number 4 was the number of the move at which game is won by player O. What am I doing wrong? Thanks!

Quandray     2016-12-12 07:23:07
User avatar

Hi,

In your example, the winning position is 4 but that's move number 8

3 1 2 5 8 6 7 4 9  move position
1 2 3 4 5 6 7 8 9  move number
             /^\

When testing your code, I suggest you start off with the example "input data" and answer

Cl3r1k     2016-12-12 09:03:23
User avatar

Thanks a lot. Now I got the idea. -> Answer should contain the NUMBER of the MOVE. It is all my bad English. Thanks again!

omsarmiento1953     2023-02-27 06:08:56

This is the example data input data: 3 7 5 4 1 9 2 8 3 6 5 1 3 7 6 4 2 9 8 5 1 2 8 6 4 7 3 9

answer: 7 6 0

For the first line my answer is 8... reason O last is 1 2 3 which is a winning combination and 3 is the winning move and is located at position 8 of the line.

The example's answer is 7... X last is 4 9 8 which is not a winning combination... I do not understand this.

X   X   X
|   |   |

7 5 4 1 9 2 8 3 6 | | | O O O

1 2 3 4 5 6 7 8 9

zelevin     2023-02-27 06:18:38

In the first example, on move 7 the X player completes the bottom row (7, 8, 9). This is exactly the game that is analyzed in great detail in the problem's description.

In the second example, the O player completes the (1, 4, 7) column on the 6th move.

In the third example, neither player wins.

I don't quite understand your argument that "X last is 4 9 8". In Tic Tac Toe, all moves count, not just the three most recent.

Hope this helps.

omsarmiento1953     2023-02-27 06:31:48

OK! I got it! I missed the combination X's 7 9 8. Thanks for the response.

zelevin     2023-02-27 06:47:23

You are perfectly welcome. Thanks to you as well - this gave me a chance to revise my own solution into something much leaner.

Please login and solve 5 problems to be able to post at forum