Number of lines in a tic tac toe of width $w$ and dimension $d$

215 Views Asked by At

I was watching a video by pbs infinite series on tic-tac-toe(https://www.youtube.com/watch?v=FwJZa-helig). Here, they discuss if there is a winning strategy for the starting player in tic-tac-toe of dimension $d$ and width $w$ . I was trying to calculate the number of lines that are possible in a board, i.e, no. of lines that can result in a win for a board of arbitrary dimension and width. I want a formula which gives No. of lines $= f(d,w)$ . For example, a $3*3$ tic tac toe has $8$ winning lines. For $2$ dimension, it is easy to see that this number is $2*(w+1) , w$ horizontal, $w$ vertical and $2$ diagonal. But I couldn't generalize this to arbitrary dimensions.

1

There are 1 best solutions below

0
On BEST ANSWER

I think I have solved this question. After some thinking, you can find that the formula is $\frac{(w+2)^d-(w)^d}{2}$. This comes if you index the tic tac toe board. Now, the valid lines are ones in which 1 or more indexes are changing. The total ways in which indexes can increase or decrease or remain the same is $(w+2)^d$. You also have to subtract the cases in which all the indexes remain the same, which are $w^d$. Also, the cases in which the indexes follow the reverse order are the same, i.e, one index increasing and the other decreasing is the same as one decreasing and other increasing. Hence, a factor of 2 has to be divided.