From with moves, you can go up, down, left, or right. The formula: Base case: if is outside the grid, return . That path successfully left.
If and you're still inside, return . No moves left, didn't escape. Don't forget: take results modulo since counts can get huge. Each cell receives probability from its four neighbors. The grid acts like a probability distribution over positions.