17
3
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.
1The Ruby answer isn't the shortest, so it should not be the accepted answer according to your scoring criteria (code-golf). – mbomb007 – 2015-04-13T16:27:50.703
2
I'm getting different numbers here: 212256 wins for X, 104544 wins for O and 46080 draws (and Wikipedia seems to agree with me).
– Ventero – 2011-02-19T15:04:34.763@Ventero, I'll recheck, but I don't see any reference to those numbers on the page. – st0le – 2011-02-19T15:15:24.413
@Ventero, You're right, i'll edit that part. will post the md5sum soon. – st0le – 2011-02-19T15:17:39.203