lichess.org
Donate

Math in Chess

In how many different ways can a king on e1 reach the e8 square in just 7 moves?
Example 1- e2,e3,e4,e5,e6,e7,e8
Example 2- e2,e3,f4,e5,d6,e7,e8
For each 2nd to 6th move 3 possibilities are available.. So, 3^6 different ways
exactly 393 ways, my calculations may be wrong tho

Edit: proof

lets take all the squares the king can go to in order to get to e8.
list:
e2 d2 f2
c3 d3 e3 f3 g3
b4 c4 d4 e4 f4 g4 h4
b5 c5 d5 e5 f5 g5 h5
c6 d6 e6 f6 g6
d7 e7 f7

now, for each of them, calculate the number of possible squares it may go to.
Most of them have 3 possible squares to go to, but some of them just have 1 or 2

Now the calculations:
for d7, e7 and f7 the number of possible paths is 1.
Now for each square, the number of possible paths is the sum of the number of possible paths of the squares that can be reached from that square (Knowing that the king must only go forward)

Following the pattern we get that from e1 the number of possible paths is 393
sry for my bad english
<Comment deleted by user>
@Imshahid said in #3:
> For each 2nd to 6th move 3 possibilities are available.. So, 3^6 different ways
That is not true. If after going right three times in a row and then one time straigt up, there is only one move for the last three moves (going left), otherwise you cannot come back to the e-line.
@LillyHedgehog said in #6:
> That is not true. If after going right three times in a row, there is only one move (going left), otherwise you cannot come back to the e-line.
Yeah its more complicated than I thought. Need to consider left and right moves separately as no 2 or 3 consecutive left or right moves are possible.
After a bit of research, apparently there is actually a formal name for this problem in mathematics: Grand Motzkin paths, with the number of ways to move n rows in n moves being apparently equivalent to the largest coefficient of (x^2 + x + 1)^n (see oeis.org/A002426). In the case of n = 7 (which is what this specific problem deals with), the answer is apparently indeed 393, as @abduskan64 mentioned.
I wrote a small python program that solves it, and it says 393. (edit: I replaced all leading spaces in a line with "_", otherwise you cannot see the indention of the code)

states = [-1,0,1] #going left up, straight up, or right up.
current = [[-1],[0],[1]] #initial possibilites
for i in range(6): #6 more moves to add
____y = []
____for x in current:
________for j in range(3):
____________tmp = x[:] #avoiding a list-problem in python
____________tmp.append(states[j])
____________y.append(tmp)
____current = y
#current now holds a list of all possible and impossible 7-moves (so it is the 7-tensor of [-1,0,1])

isFine = [0 for i in range(len(current))]#all moves that oblige the given rules (but not yet)
for i in range(len(current)):
____x = current[i][:]#avoiding a list-problem in python
____tmp = 0
____for y in x:
________tmp += y
________if tmp>3 or tmp<-4: #if we make more than 4 moves to the left or 3 moves to the right, we leave the board.
____________break
____if tmp==0:#did we get back to the e-file after all moves made?
________isFine[i]=1
print(sum(isFine))

This topic has been archived and can no longer be replied to.