Skip to main content
added 1 character in body
Source Link
Jos Woolley
  • 1.9k
  • 1
  • 2

Tic-Tac-Toe: Maintain the Draw!

Tic-Tac-Toe is a game for two players who take turns marking the spaces in a 3x3 grid with an X or aan O. If a player succeeds in placing three of their marks in a horizontal, vertical or diagonal line they are the winner; otherwise, the game is considered drawn.

Challenge

You have been chosen to represent the human race in a game of Tic-Tac-Toe against the AIs. Dauntingly, your opponent is a programme which always finds the optimal move in a given position. Worse still, you will be playing second. The only consolation is that you are required to survive for one move only: that is, you must make a single move in reply to the computer's opening gambit which leads to a position which is not theoretically lost. If you find such a move, humanity lives to fight another day; if not, ...

Assuming a Tic-Tac-Toe board with the following notation

1 2 3
4 5 6
7 8 9

given the AI's opening move output all possible replies which do not lead to a theoretically lost position.

Input

An integer \$n\$ (where \$1<=n<=9\$) which represents the machine's opening move as per the given board notation.

Output

A sorted list, array, etc. of integers which represents all possible solutions.

Explained Cases

Input => Output

1 => [5]
The only reply to a corner-square opening move which does not lead to a theoretical loss
is that which occupies the central square.

2 => [1, 3, 5, 8]

The only replies to an edge-square opening move which do not lead to a theoretical loss
are those which occupy the same row or column as that of your opponent's move.

5 => [1, 3, 7, 9]

The only replies to a central-square opening move which do not lead to a theoretical
loss are those which occupy one of the four corner squares.

Test Cases

Input => Output

1 => [5]
2 => [1, 3, 5, 8]
3 => [5]
4 => [1, 5, 6, 7]
5 => [1, 3, 7, 9]

This is , so shortest answer in bytes wins!

Tic-Tac-Toe: Maintain the Draw!

Tic-Tac-Toe is a game for two players who take turns marking the spaces in a 3x3 grid with an X or a O. If a player succeeds in placing three of their marks in a horizontal, vertical or diagonal line they are the winner; otherwise, the game is considered drawn.

Challenge

You have been chosen to represent the human race in a game of Tic-Tac-Toe against the AIs. Dauntingly, your opponent is a programme which always finds the optimal move in a given position. Worse still, you will be playing second. The only consolation is that you are required to survive for one move only: that is, you must make a single move in reply to the computer's opening gambit which leads to a position which is not theoretically lost. If you find such a move, humanity lives to fight another day; if not, ...

Assuming a Tic-Tac-Toe board with the following notation

1 2 3
4 5 6
7 8 9

given the AI's opening move output all possible replies which do not lead to a theoretically lost position.

Input

An integer \$n\$ (where \$1<=n<=9\$) which represents the machine's opening move as per the given board notation.

Output

A sorted list, array, etc. of integers which represents all possible solutions.

Explained Cases

Input => Output

1 => [5]
The only reply to a corner-square opening move which does not lead to a theoretical loss
is that which occupies the central square.

2 => [1, 3, 5, 8]

The only replies to an edge-square opening move which do not lead to a theoretical loss
are those which occupy the same row or column as that of your opponent's move.

5 => [1, 3, 7, 9]

The only replies to a central-square opening move which do not lead to a theoretical
loss are those which occupy one of the four corner squares.

Test Cases

Input => Output

1 => [5]
2 => [1, 3, 5, 8]
3 => [5]
4 => [1, 5, 6, 7]
5 => [1, 3, 7, 9]

This is , so shortest answer in bytes wins!

Tic-Tac-Toe: Maintain the Draw!

Tic-Tac-Toe is a game for two players who take turns marking the spaces in a 3x3 grid with an X or an O. If a player succeeds in placing three of their marks in a horizontal, vertical or diagonal line they are the winner; otherwise, the game is considered drawn.

Challenge

You have been chosen to represent the human race in a game of Tic-Tac-Toe against the AIs. Dauntingly, your opponent is a programme which always finds the optimal move in a given position. Worse still, you will be playing second. The only consolation is that you are required to survive for one move only: that is, you must make a single move in reply to the computer's opening gambit which leads to a position which is not theoretically lost. If you find such a move, humanity lives to fight another day; if not, ...

Assuming a Tic-Tac-Toe board with the following notation

1 2 3
4 5 6
7 8 9

given the AI's opening move output all possible replies which do not lead to a theoretically lost position.

Input

An integer \$n\$ (where \$1<=n<=9\$) which represents the machine's opening move as per the given board notation.

Output

A sorted list, array, etc. of integers which represents all possible solutions.

Explained Cases

Input => Output

1 => [5]
The only reply to a corner-square opening move which does not lead to a theoretical loss
is that which occupies the central square.

2 => [1, 3, 5, 8]

The only replies to an edge-square opening move which do not lead to a theoretical loss
are those which occupy the same row or column as that of your opponent's move.

5 => [1, 3, 7, 9]

The only replies to a central-square opening move which do not lead to a theoretical
loss are those which occupy one of the four corner squares.

Test Cases

Input => Output

1 => [5]
2 => [1, 3, 5, 8]
3 => [5]
4 => [1, 5, 6, 7]
5 => [1, 3, 7, 9]

This is , so shortest answer in bytes wins!

added 2 characters in body
Source Link
Jos Woolley
  • 1.9k
  • 1
  • 2

Tic-Tac-Toe: Maintain the Draw!

Tic-Tac-Toe is a game for two players who take turns marking the spaces in a 3x3 grid with an X or a O. If a player succeeds in placing three of their marks in a horizontal, vertical or diagonal line they are the winner; otherwise, the game is considered drawn.

Challenge

You have been chosen to represent the human race in a game of Tic-Tac-Toe against the AIs. Dauntingly, your opponent is a programme which always finds the optimal move in a given position. Worse still, you will be playing second. The only consolation is that you are required to survive for one move only: that is, you must make a single move in reply to the computer's opening gambit which leads to a position which is not theoretically lost. If you find such a move, humanity lives to fight another day; if not, ...

Assuming a Tic-Tac-Toe board with the following notation

1 2 3
4 5 6
7 8 9

given the AI's opening move output all possible replies which do not lead to a theoretically lost position.

Input

An integer \$n\$ where (where \$1<=n<=9\$) which represents the machine's opening move as per the given board notation.

Output

A sorted list, array, etc. of integers which represents all possible solutions.

Explained Cases

Input => Output

1 => [5]
The only reply to a corner-square opening move which does not lead to a theoretical loss
is that which occupies the central square.

2 => [1, 3, 5, 8]

The only replies to an edge-square opening move which do not lead to a theoretical loss
are those which occupy the same row or column as that of your opponent's move.

5 => [1, 3, 7, 9]

The only replies to a central-square opening move which do not lead to a theoretical
loss are those which occupy one of the four corner squares.

Test Cases

Input => Output

1 => [5]
2 => [1, 3, 5, 8]
3 => [5]
4 => [1, 5, 6, 7]
5 => [1, 3, 7, 9]

This is , so shortest answer in bytes wins!

Tic-Tac-Toe: Maintain the Draw!

Tic-Tac-Toe is a game for two players who take turns marking the spaces in a 3x3 grid with an X or a O. If a player succeeds in placing three of their marks in a horizontal, vertical or diagonal line they are the winner; otherwise, the game is considered drawn.

Challenge

You have been chosen to represent the human race in a game of Tic-Tac-Toe against the AIs. Dauntingly, your opponent is a programme which always finds the optimal move in a given position. Worse still, you will be playing second. The only consolation is that you are required to survive for one move only: that is, you must make a single move in reply to the computer's opening gambit which leads to a position which is not theoretically lost. If you find such a move, humanity lives to fight another day; if not, ...

Assuming a Tic-Tac-Toe board with the following notation

1 2 3
4 5 6
7 8 9

given the AI's opening move output all possible replies which do not lead to a theoretically lost position.

Input

An integer \$n\$ where \$1<=n<=9\$ which represents the machine's opening move as per the given board notation.

Output

A sorted list, array, etc. of integers which represents all possible solutions.

Explained Cases

Input => Output

1 => [5]
The only reply to a corner-square opening move which does not lead to a theoretical loss
is that which occupies the central square.

2 => [1, 3, 5, 8]

The only replies to an edge-square opening move which do not lead to a theoretical loss
are those which occupy the same row or column as that of your opponent's move.

5 => [1, 3, 7, 9]

The only replies to a central-square opening move which do not lead to a theoretical
loss are those which occupy one of the four corner squares.

Test Cases

Input => Output

1 => [5]
2 => [1, 3, 5, 8]
3 => [5]
4 => [1, 5, 6, 7]
5 => [1, 3, 7, 9]

This is , so shortest answer in bytes wins!

Tic-Tac-Toe: Maintain the Draw!

Tic-Tac-Toe is a game for two players who take turns marking the spaces in a 3x3 grid with an X or a O. If a player succeeds in placing three of their marks in a horizontal, vertical or diagonal line they are the winner; otherwise, the game is considered drawn.

Challenge

You have been chosen to represent the human race in a game of Tic-Tac-Toe against the AIs. Dauntingly, your opponent is a programme which always finds the optimal move in a given position. Worse still, you will be playing second. The only consolation is that you are required to survive for one move only: that is, you must make a single move in reply to the computer's opening gambit which leads to a position which is not theoretically lost. If you find such a move, humanity lives to fight another day; if not, ...

Assuming a Tic-Tac-Toe board with the following notation

1 2 3
4 5 6
7 8 9

given the AI's opening move output all possible replies which do not lead to a theoretically lost position.

Input

An integer \$n\$ (where \$1<=n<=9\$) which represents the machine's opening move as per the given board notation.

Output

A sorted list, array, etc. of integers which represents all possible solutions.

Explained Cases

Input => Output

1 => [5]
The only reply to a corner-square opening move which does not lead to a theoretical loss
is that which occupies the central square.

2 => [1, 3, 5, 8]

The only replies to an edge-square opening move which do not lead to a theoretical loss
are those which occupy the same row or column as that of your opponent's move.

5 => [1, 3, 7, 9]

The only replies to a central-square opening move which do not lead to a theoretical
loss are those which occupy one of the four corner squares.

Test Cases

Input => Output

1 => [5]
2 => [1, 3, 5, 8]
3 => [5]
4 => [1, 5, 6, 7]
5 => [1, 3, 7, 9]

This is , so shortest answer in bytes wins!

added 12 characters in body
Source Link
Jos Woolley
  • 1.9k
  • 1
  • 2

Tic-Tac-Toe: Maintain the Draw!

Tic-Tac-Toe is a game for two players who take turns marking the spaces in a 3x3 grid with an X or a O. If a player succeeds in placing three of their marks in a horizontal, vertical or diagonal line they are the winner; otherwise, the game is considered drawn.

Challenge

You have been chosen to represent the human race in a game of Tic-Tac-Toe against the AIs. Dauntingly, your opponent is a programme which always finds the optimal move in a given position. Worse still, you will be playing second. The only consolation is that you are required to survive for one move only: that is, you must make a single move in reply to the computer's opening gambit which leads to a position which is not theoretically lost. If you find such a move, humanity lives to fight another day; if not, ...

Assuming a Tic-Tac-Toe board with the following notation

1 2 3
4 5 6
7 8 9

given the AI's opening move output all possible replies which do not lead to a theoretically lost position.

Input

An integer \$n\$ where \$1<=n<=9\$ which represents the machine's opening move as per the given board notation.

Output

A sorted list, array, etc. of integers which representrepresents all possible solutions.

Explained Cases

Input => Output

1 => [5]
The only reply to a corner-square opening move which does not lead to a theoretical loss
is that which occupies the central square.

2 => [1, 3, 5, 8]

The only replies to an edge-square opening move which do not lead to a theoretical loss
are those which occupy the same row or column as that of your opponent's move.

5 => [1, 3, 7, 9]

The only replies to a central-square opening move which do not lead to a theoretical
loss are those which occupy one of the four corner squares.

Test Cases

Input => Output

1 => [5]
2 => [1, 3, 5, 8]
3 => [5]
4 => [1, 5, 6, 7]
5 => [1, 3, 7, 9]

This is , so shortest answer in bytes wins!

Tic-Tac-Toe: Maintain the Draw!

Tic-Tac-Toe is a game for two players who take turns marking the spaces in a 3x3 grid with an X or a O. If a player succeeds in placing three of their marks in a horizontal, vertical or diagonal line they are the winner; otherwise, the game is considered drawn.

Challenge

You have been chosen to represent the human race in a game of Tic-Tac-Toe against the AIs. Dauntingly, your opponent is a programme which always finds the optimal move in a given position. Worse still, you will be playing second. The only consolation is that you are required to survive for one move only: that is, you must make a single move in reply to the computer's opening gambit which leads to a position which is not theoretically lost. If you find such a move, humanity lives to fight another day; if not, ...

Assuming a Tic-Tac-Toe board with the following notation

1 2 3
4 5 6
7 8 9

given the AI's opening move output all possible replies which do not lead to a theoretically lost position.

Input

An integer \$n\$ where \$1<=n<=9\$ which represents the machine's opening move as per the given board notation.

Output

A list, array, etc. of integers which represent possible solutions.

Explained Cases

Input => Output

1 => [5]
The only reply to a corner-square opening move which does not lead to a theoretical loss
is that which occupies the central square.

2 => [1, 3, 5, 8]

The only replies to an edge-square opening move which do not lead to a theoretical loss
are those which occupy the same row or column as that of your opponent's move.

5 => [1, 3, 7, 9]

The only replies to a central-square opening move which do not lead to a theoretical
loss are those which occupy one of the four corner squares.

Test Cases

Input => Output

1 => [5]
2 => [1, 3, 5, 8]
3 => [5]
4 => [1, 5, 6, 7]
5 => [1, 3, 7, 9]

This is , so shortest answer in bytes wins!

Tic-Tac-Toe: Maintain the Draw!

Tic-Tac-Toe is a game for two players who take turns marking the spaces in a 3x3 grid with an X or a O. If a player succeeds in placing three of their marks in a horizontal, vertical or diagonal line they are the winner; otherwise, the game is considered drawn.

Challenge

You have been chosen to represent the human race in a game of Tic-Tac-Toe against the AIs. Dauntingly, your opponent is a programme which always finds the optimal move in a given position. Worse still, you will be playing second. The only consolation is that you are required to survive for one move only: that is, you must make a single move in reply to the computer's opening gambit which leads to a position which is not theoretically lost. If you find such a move, humanity lives to fight another day; if not, ...

Assuming a Tic-Tac-Toe board with the following notation

1 2 3
4 5 6
7 8 9

given the AI's opening move output all possible replies which do not lead to a theoretically lost position.

Input

An integer \$n\$ where \$1<=n<=9\$ which represents the machine's opening move as per the given board notation.

Output

A sorted list, array, etc. of integers which represents all possible solutions.

Explained Cases

Input => Output

1 => [5]
The only reply to a corner-square opening move which does not lead to a theoretical loss
is that which occupies the central square.

2 => [1, 3, 5, 8]

The only replies to an edge-square opening move which do not lead to a theoretical loss
are those which occupy the same row or column as that of your opponent's move.

5 => [1, 3, 7, 9]

The only replies to a central-square opening move which do not lead to a theoretical
loss are those which occupy one of the four corner squares.

Test Cases

Input => Output

1 => [5]
2 => [1, 3, 5, 8]
3 => [5]
4 => [1, 5, 6, 7]
5 => [1, 3, 7, 9]

This is , so shortest answer in bytes wins!

Source Link
Jos Woolley
  • 1.9k
  • 1
  • 2
Loading