A TicTacToe
game can be represented by a string denoting the sequence of positions as the players make their move.
0 1 2 3 4 5 6 7 8
Assume X
always plays first.
So a string of "012345678" denotes the game
X O X O X O X O X
Notice, the game is already won when Player X
marks 6
, at that point the game ends, granting a win to X
. (ie, ignore the remaining moves once a player wins)
Your challenge (code) is to print all the games (sorted order) and its results.
The Format
<movesequence>:<result>\n
eg:
012345678:X
012345687:X
012345768:X
...
Denote X
for the 1st player winning, O
for the second player, and D
for Draws.
There will be 9!
(362880) games.
Here is some data to verify your results.
'X' Wins: 212256
'O' Wins: 104544
Draws : 46080
This is a codegolf, and runtime should be within a minute. Have Fun!
EDIT: Removed excess details, and just print it on stdout
. No need to create a file.