Walking on an infinite grid

We encode the steps with $x$ when going a step horizontally in $x$-direction and with $y$ when going vertically in $y$-direction. This way $A,B,C$ become \begin{align*} &A=(1,0)\quad\to x^1y^0\\ &B=(1,1)\quad \to x^1y^1\\ &C=(1,-1)\ \to x^1y^{-1}\\ \end{align*} To go one step either $A$ or $B$ or $C$ is encoded as \begin{align*} x+xy+\frac{x}{y} \end{align*}

Note the number of paths from $(2,2)$ to $(42,2)$ is due to symmetry equal to the number of paths from $(0,0)$ to $(40,0)$. We need $40$ steps to go from $(0,0)$ to $(40,0)$ and so we consider \begin{align*} [x^{40}y^{0}]\left(x+xy+\frac{x}{y}\right)^{40}\tag{1} \end{align*} where we conveniently use the coefficient of operator $[x^ny^m]$ to denote the coefficient of $x^ny^m$ in a series $A(x,y)$.

We obtain \begin{align*} \color{blue}{[x^{40}y^{0}]}&\color{blue}{\left(x+xy+\frac{x}{y}\right)^{40}}\\ &=[x^{40}y^0]x^{40}\left(1+y+\frac{1}{y}\right)^{40}\\ &=[y^0]\sum_{k=0}^{40}\binom{40}{k}\left(y+\frac{1}{y}\right)^k\tag{2}\\ &=[y^0]\sum_{k=0}^{40}\binom{40}{k}\sum_{j=0}^k\binom{k}{j}y^jy^{-(k-j)}\\ &=\sum_{k=0}^{40}\binom{40}{k}[y^k]\sum_{j=0}^k\binom{k}{j}y^{2j}\tag{3}\\ &=\sum_{k=0}^{20}\binom{40}{2k}[y^{2k}]\sum_{j=0}^{2k}\binom{2k}{j}y^{2j}\tag{4}\\ &\,\,\color{blue}{=\sum_{k=0}^{20}\binom{40}{2k}\binom{2k}{k}}\tag{5} \end{align*} in accordance with the result of @JeanMarie.

Comment:

  • In (2) we apply the rule $[x^p]x^q=[x^{p-q}]$ and apply the binomial theorem to $\left(1+\left(y+\frac{1}{y}\right)\right)^{40}$.

  • In (3) we apply the rule $[y^p]y^q=[y^{p-q}]$ again.

  • In (4) we observe that only even powers $2j$ do contribute. So we need only to consider even indices $2k$.

  • In (5) we finally select the coefficient of $y^{2k}$.

Note: The coefficients of $x^0$ in the expansion of $\left(x+1+x^{-1}\right)^n$ are called central trinomial coefficients. They do not admit a closed formula which is shown in this post.


First of all, your problem is equivalent to find the number of paths from $(0,0)$ to $(40,0)$. This is what we are going to assume.

Considering $A,B,C$ as vectors, we are in a first step looking for the number of triples $(m,n,p)$ of integers such that $$m\binom{1}{0}+n\binom{1}{1}+p\binom{ \ \ 1}{-1}=\binom{40}{0} \ \iff \ \ \begin{cases}m+n+p&=&40\\n-p&=&0\end{cases}\tag{1}$$

$$\iff \ \ \begin{cases}m+2n&=&40& \ \ \ (a)\\n&=&p& \ \ \ (b)\end{cases}.\tag{2}$$ which amounts to say :

$$\text{Determine (first) the ordered pairs of integers} \ (m,n) \ \text{such that} \ m+2n=40$$

(2) implies that $m=2(20-n)$ is an even number : $m=2k$ for $k=0,1,\cdots 20.$

Therefore, taking (2)(b) into account :

$$(m,n,p)=(2k,20-k,20-k)=(0,20,20),(2,19,19),(4,18,18), etc...$$

As a consequence, each $k$ it remains to constitute a word of $40$ letters $A,B,C$, i.e.

place into $40$ slots : $m=2k$ letters "$A$"s, $(20-k)$ letters "$B$"s, and $(20-k)$ letters "$C$"s as well.

Once the $2k$ "slots" for letters "$A$" have been attributed, we have to place the same amount of letters $B$ and $C$ i.e., $20-k$ letters $B$ and as many letters "$C$". We consider only placement of letters "$B$" (Placing letters "$C$" hasn't to be considered : they occupy the remaining "slots"). This boils down to the following count :

$$\sum_{k=0}^{20} \binom{40}{2k}\binom{40-2k}{20-k}=\sum_{k=0}^{20} \frac{40 !}{(2k)! (20-k) ! (20-k) !}$$

I don't know if one can give a close expression to this sum...