Let's play some code golf!
Given a tic-tac-toe board state (Example:)
|x|x|o|
|x|o|x|
|o|o|x|
Determine whether a game is a win
a lose
or cat
. Your code should output any of these options given a state. The above game should output lose
Just to be clear: a win is defined as any 3 x
s in a row (diagonal, horizontal, vertical). a lose is 3 o
s in a row, while a cat
game in none in a row.
To make things interesting, you get to determine your input structure for the state- which you must then explain. For instance xxoxoxoox
is a valid state as seen above where each of the characters is read from left to right, top to bottom. [['x','x','o'],['x','o','x'],['o','o','x']]
is the game in multidimensional array read in a similar way. While 0x1a9
which is hex for 110101001
might work as a suitable compression where 1
can be manipulated for x
s and 0
can be manipulated for o
.
But those are just some ideas, I'm sure you might have many of your own.
Ground rules:
- Your program must be able to accept any viable state.
- The form of input must be able to represent any state.
- The input cannot be redundant, meaning each cell must only appear in one location.
- "The win state must be determined from the board"
- Assume a complete board
Win
beforelose
for instance in the case 'xxxoooxxx'
Lowest character count wins
win
,lose
,cat
. For input it must be from a human (not randomly generated). Thus usingdef q(x):#magic code here
works just as well as(/*magic code */)(prompt())
\$\endgroup\$