title: Tic Tac Toe: How to prove that there are 26,830 games possibilities
body: <p>I used the below code to get some statistics about the tic tac toe, I'm able to get the following numbers:</p>
  
  <p>There are 138 terminal positions after assuming symmetries.</p>
  
  <p>765 Positions</p>
  
  <p>91 (X)</p>
  
  <p>44 (O)</p>
  
  <p>3 (tie)</p>
  
  <p>But how to get the 26,830 games possibilities, from where I can extract and print this number?</p>
  
  <p>The code I'm using created by <a href="https://codegolf.stackexchange.com/users/69880/chas-brown">@Chas Brown</a></p>
  
  <p>Original question: <a href="https://codegolf.stackexchange.com/questions/123058/tic-tac-toe-print-all-possible-positions-without-duplicates">Here</a></p>
  
  <pre><code>import re
  from collections import Counter
  
  FLIP_XFRM = [2,1,0,5,4,3,8,7,6]
  ROT_XFRM = [6,3,0,7,4,1,8,5,2]
  
  def xfrm(b, xf):
      return ''.join(b[xf[i]] for i in range(9))
  
  def flipIt(b):
      return xfrm(b,FLIP_XFRM)
  
  def rotIt(b):
      return xfrm(b,ROT_XFRM)
  
  def conjugates(b):
      conj = [b, flipIt(b)]
      for i in range(3):
          conj += [rotIt(conj[-2]), rotIt(conj[-1])]
      return conj
  
  def tttToB(n):
      b = ''
      for i in range(9):
          b = '.XO'[n %3]+b
          n /= 3
      return b
  
  def printBoard(b,outcome='.'):
      print '%s\n%s\n%s %s\n' % (b[:3],b[3:6],b[6:],outcome)
  
  def evalBoard(b):
      c = Counter(b)
      if c['X']-c['O'] not in [0,1]:
          return False
  
      p1 = 'XXX......|...XXX...|......XXX|X...X...X'
      p2 = p1.replace('X','O')
  
      br = rotIt(b)
      w1 = re.match(p1,b) or re.match(p1,br)    
      w2 = re.match(p2,b) or re.match(p2,br)    
      if w1 and w2:
          return False
  
      if w1:
          return 'X' if c['X']==c['O']+1 else False
  
      if w2:
          return 'O' if c['X']==c['O'] else False
  
      if '.' in b:
          return '.'
      else:
          return '/'
  
  def main():
      history = set()
      for m in range(3**9):
          b = tttToB(m)
          if b not in history:
              outcome = evalBoard(b)
              if outcome:
                  printBoard(b,outcome)
              history.update(conjugates(b))
  
  main()
  </code></pre>