Generate a list of all unique Tic Tac Toe boards

前端 未结 7 2038

I would like to generate a text file containing all 19,683 Tic-Tac-Toe board layouts in the structure of 0 = Blank, 1 = X, and 2 = O. Unfortunately math is not my strong su

7条回答
  •  别那么骄傲
    2020-12-30 09:35

    Like an earlier solution, but easier to read and in Python.

    for i in range(3**9):
         c = i
         for j in range(9):
             if j % 3 == 0:
                 print("")
             print(str(c % 3) + " ", end='')
             c //= 3
         print("")
    

提交回复
热议问题