Context: My friend gave me a problem at breakfast some time ago. It is supposed to have an easy, trick-involving solution. I can't figure it out.
Problem: Let there be a knight (horse) at a particular corner (0,0) on a 8x8 chessboard. The knight moves according to the usual rules (2 in one direction, 1 in the orthogonal one) and only legal moves are allowed (no wall tunnelling etc). The knight moves randomly (i.e. at a particular position, it generates a set of all possible and legal new positions, and picks one at random). What is the average number of steps after which the knight returns to its starting corner?
To sum up: A knight starts at (0,0). How many steps on average does it take to return back to (0,0) via a random (but only legal knight moves) walk.
My attempt: (disclaimer: I don't know much about Markov chains.)
The problem is a Markov chain. There are $8\times8 = 64$ possible states. There exist transition probabilities between the states that are easy to generate. I generated a $64 \times 64$ transition matrix $M_{ij}$ using a simple piece of code, as it seemed too big to do by hand.
The starting position is $v_i = (1,0,0,...) = \delta_{0i}$.
The probability that the knight as in the corner (state 0) after $n$ steps is $$ P_{there}(n) = (M^n)_{0j} v_j \, . $$ I also need to find the probability that the knight did not reach the state 0 in any of the previous $n-1$ steps. The probability that the knight is not in the corner after $m$ steps is $1-P_{there}(m)$.
Therefore the total probability that the knight is in the corner for the first time (disregarding the start) after $n$ steps is $$ P(n) = \left ( \prod_{m=1}^{n-1} \left [ 1 - \sum_{j = 0}^{63} (M^m)_{0j} v_j \right ] \right ) \left ( \sum_{j = 0}^{63} (M^n)_{0j} v_j \right ) $$ To calculate the average number of steps to return, I evaluate $$ \left < n \right >= \sum_{n = 1}^{\infty} n P(n) \, . $$ My issue: The approach I described should work. However, I had to use a computer due to the size of the matrices. Also, the $\left < n \right >$ seems to converge quite slowly. I got $\left < n \right > \approx 130.3$ numerically and my friend claims it's wrong. Furthermore, my solution is far from simple. Would you please have a look at it?
Thanks a lot! -SSF
Details of the method mentioned in @Batman's comment:
We can view each square on the chessboard as a vertex on a graph consisting of $64$ vertices, and two vertices are connected by an edge if and only if a knight can move from one square to another by a single legal move.
Since knight can move to any other squares starting from a random square, then the graph is connected (i.e. every pair of vertices is connected by a path).
Now given a vertex $i$ of the graph, let $d_i$ denote the degree of the vertex, which is number of edges connected to the vertex. This is equivalent to number of possible moves that a knight can make at that vertex (square on chessboard). Since the knight moves randomly, transition probabilities from $i$ to its neighbors is $1/d_i$.
Now since the chain is irreducible (since the graph is connected) the stationary distribution of the chain is unique. Let's call this distribution $\pi$. Now we claim the following:
Therefore, it follows that after normalising we have
$$ \pi_j=d_j/\sum_i d_i $$
Finally we recall the following theorem
Thus if we call the corner vertex $1$, we have
$$ m_1=1/\pi_1 $$
You can check that $\sum_i d_i = 336$, and we have $d_1=2$ (at corner knight can make at most $2$ legal moves. Therefore $\pi_1=1/168$ and
$$ m_1=168 $$