The Tic Tac Toe Dictionary 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

&lt;movesequence&gt;:&lt;result&gt;\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.
J, 124 chars

((],~':',~1":[){&amp;'DOX'@(&lt;/+2*&gt;/)@:(&lt;./"1)@:(((2{m/.@|.),(2{m/.),m"1,&gt;./)"2)@(&lt;:@(&gt;:%2|]),:(%(2|&gt;:)))@(3 3$]))"1((i.!9)A.i.9)


X win, O win and Draw counts check out.

Was a bit painful to debug though. :)