You can find the answer here, namely , but I don't know how to justify that rigorously.

If you want to get a feel for how this works, try to work out how many routes there are for a smaller number of steps, say four steps or six steps, which should be easier than 40 steps. As an example, in the case of four steps there are nine lattice points that you can reach after two steps (including the origin itself, which you can reach in four ways). For each of these, write down how many ways there are of getting there in two steps. You should arrive at a picture like this:

Code:

1
2 . 2
1 . 4 . 1
2 . 2
1

(The dots indicate points like (1,0) that you can't reach after two moves.) For each of these destinations, there is an equal number of ways of getting back to the origin after another two moves. So the total number of ways of getting back to the origin after four moves is . Notice that if you look along the diagonals (is that where the hint about the 45-degree rotation comes from?), you see the binomial coefficients 1,2,1 multiplied by 1,2,1. For a journey of 2n steps, that suggests that the total number of possible routes is , which is equal to .