Delannoy numbers
The solution for a $n+1$ by $m+1$ grid is given by Delannoy numbers
$D(n,m) = \Sigma_{d=0}^{n} \ ^mC_d \ ^{n+m-d}C_m$
note this assumes n<=m, we can easily express the dimensions either way round to achievement this
Derivation
There are 3 possible moves, $(1,0), (0,1)$ or $(1,1)$
for $n+1$ by $m+1$ board we must move a total of $(n,m)$ this is made using using any combination of the 3 moves such that:
$num(1,0) +num(1,1) = n$
$num(0,1) + num(1,1) = m$
we can decide how many of $(1,0)$ and $(0,1)$ to use based on the numebr of $(1,1)$s
Starting with diagonal moves
As n is the smaller dimension there are between 0 and n $(1,1)$s (diagonal moves) in any solution
so lets look at how they can be arranged (ignoring the other entries)
- for 0 $(1,1)$s there is 1 (or $\ ^nC_0$) possible arrangement
- for 1 $(1,1)$s there are $\ ^nC_1$ possible arrangements
and so on until
- for n $(1,1)$s there are $\ ^nC_n$ possible arrangements
in generality
- for $d$ (1,1)s there are $\ ^nC_{d}$ possible arrangements
- and d must fall between 0 and n (inclusive)
so there are in total $\Sigma_{d=0}^{n} \ ^kC_d$ possible locations for moves of $(1,1)$ in an $n+1$ by $m+1$ grid.
Now the non-diagonal moves
For each of these numbers of (1,1)s there is also many ways to arrange the (0,1)s and (1,0)s
For 0 $(1,1)$s
- there must be $n (1,0)$s out of a total number of moves of $n+m$
- i.e. there must be $n (1,0)$s and $m (0,1)$s
so there is $\ ^{n+m}C_m $ possible arrangements
Now for $1 (1,1)$
- there must be $n-1 (1,0)$s out of a total number of positions of $n+m-2$,
- i.e. there must be $n-1 (1,0)$s and $m-1 (0,1)$s
- one position is already $(1,1)$ so there are $n+m-1$ locations that can be taken
There are $\ ^{n+m-1}C_m$ possible arrangements of $(0,1)$ and $(1,1)$ for each location of the one $(1,1)$.
Giving $\ ^nC_1 \ ^{n+m-1}C_m $ arrangements possible for 1 diagonal move
In generality for $d (1,1)$s
There are $\ ^nC_d \ ^{n+m-d}C_m $ possible arrangements
where $d$ must again be between $0$ and $n$
So summing over all $d$ gives the overall total number of paths and gives the formula given at the beginning
$D(n,m) = \Sigma_{d=0}^{n} \ ^mC_d \ ^{n+m-d}C_m$
for 8 by 8, n=7 and m = 7 the solution as given by others is 48639