I decided to create a complete guide to the great game of tic-tac-toe.
I expected it to be extremely popular, so to save on paper while printing it I decided to encode all possible game positions.
I counted that there are exactly 6045 correct ways to put x and o on a \$3\times3\$ board.
EDIT: 6046, I forgot to count empty board.
A position is considered correct if the number of xs are equal to or one greater than the number of os.
Please help me write a function that accepts a position on the board and returns the encoded result.
This function should:
- Accept a string consisting of exactly 9 symbols
x,oor(whitespace), where all inputs are correct positions. - It should return a string consisting of exactly 13 symbols, all of which are either
1or0. - The result should be unique for every board.
You can choose which encoding algorithm you want to use.
Example
The example
|x| | |
| |o|x|
|x| |o|
Corresponds to the input x oxx o.
This is code-golf, so the shortest answer wins. All usual rules apply.
x,o, and space for the input? \$\endgroup\$