We define a nice path of length as a path on a lattice from $(0,0)$ to $(n,n)$ such as every step in it is: $r=(0,1)$ , $u=(1,0)$ and $v=(1,2)$, and it does not go under the line $y=x$.
A. Write a formula for the generating function that counts the number of the nice paths.
B.Solve the above formula and find an expression for the number of these paths of length n.
C.Find the number of $(1,2)$ steps in all paths of length n.
I started with drawing the possible paths for $n=1,2,3,4$, getting that we have $1,3,9,27$ paths (respectively) if I did really succeed to count all the possible paths for each $n$.
So, then I concluded that each legal path (which is mentioned above) is:
Every path = $\epsilon$ or v(every path) u (every path) or r(every path) u (every path).
Whhere $\epsilon$ denote the empty path.
If $A(x)$ the generating function and x denote the number of steps then I get:
$A(x)=1+(xA(x))(xA(x))+(xA(x))(xA(x))$. $A(x)=1+x^2A(x)^2+x^2A(x)^2$
In B. I can do this after extracting $A(x)$ With finding the coefficient of $x^n$ in $A(x)$.
C. I don't understand if this is related to statistics on the number of (1,2) steps..
I'm not sure if my way of thinking is correct or not, I discovered that my way is not accurate. I'll be glad if you can correct me, and explain it.
We derive a generating function $A(t)$ where $[t^n]A(t)$, the coefficient of $t^n$ in $A(t)$ gives the number of nice paths from $(0,0)$ to $(n,n)$. We conveniently encode a step in $x$-direction as $x$ corresponding to $u=(1,0)$, a step in $y$-direction as $y$ corresponding to $r=(0,1)$ and encode written in parenthesis $(xy^2)$ a step corresponding to $v=(1,2)$.
and interpret (1) as the set $\mathcal{A}$ of nice paths which is built from
the empty path or
a diagonal step of length $1$, which is realised as $yAxA$ where $A$ represents a nice path or
a diagonal step of length $2$, which is realised as $(xy^2)AxA$ where $A$ represents a nice path.
The idea here is to consider the diagonal step $yx$ with length $1$ and the diagonal step $(xy^2)x$ with length $2$ as basic building blocks.
The blue marked $31$ nice paths from $(0,0)$ to $(4,4)$ are \begin{align*} \begin{array}{llll} yyyyxxxx&yyxxyxyx&(xy^2)yxxyx&yx(xy^2)xyx\\ yyyxyxxx&yxyyyxxx&(xy^2)xyyxx&yyx(xy^2)xx\\ yyyxxyxx&yxyyxyxx&(xy^2)xyxyx&yxy(xy^2)xx\\ yyyxxxyx&yxyyxxyx&y(xy^2)yxxx&yyxx(xy^2)x\\ yyxyyxxx&yxyxyyxx&y(xy^2)xyxx&yxyx(xy^2)x\\ yyxyxyxx&yxyxyxyx&y(xy^2)xxyx&(xy^2)(xy^2)xx\\ yyxyxxyx&(xy^2)yyxxx&yy(xy^2)xxx&(xy^2)x(xy^2)x\\ yyxxyyxx&(xy^2)yxyxx&yx(xy^2)yxx\\ \end{array} \end{align*}
Note: The sequence $1,1,3,9,31,113,431,\dots$ is archived in OEIS as A052709.
Number $P_n$ of nice paths with $(1,2)$-steps:
We derive the number $P_n$ of nice paths which contain $(1,2)$-steps from the generating function $A(t;q)$. Looking again at $[t^4]A(t;q)=2q^2+15q+14$ we see we have to sum up the terms with a factor $q$ evaluated at $q=1$. We can isolate the constant term by evaluating $[t^4]A(t;q)$ at $q=0$. In order to derive the terms with factor $q$ we calculate the number of nice paths from $(0,0)$ to $(n,n)$ which contain $(1,2)$-steps as \begin{align*} P_n=[t^n]\left(A(t;1)-A(t;0)\right)\qquad\qquad n\geq 0\tag{4} \end{align*}
Number $V_n$ of $(1,2)$-steps in nice paths:
We can also count the number $V_n$ of $(1,2)$-steps in nice paths. In order to get e.g. the $\color{blue}{19}$ $(1,2)$-steps in the paths from $(0,0)$ to $(4,4)$ we differentiate $[t^4]A(t;q)$ w.r.t. $q$ and evaluate at $q=1$: \begin{align*} V_4=[t^4]\left(\left.\frac{\partial}{\partial q}A(t;q)\right|_{q=1}\right)=(4q+15)|_{q=1}\color{blue}{=19} \end{align*}
In general we have \begin{align*} V_n&=[t^n]\left(\left.\frac{\partial}{\partial q}A(t;q)\right|_{q=1}\right)\\ &=[t^n]\left.\left(\frac{t}{(1+qt)\sqrt{1-4t(1+qt))}}-\frac{1-\sqrt{1-4t(1+qt)}}{2(1+qt)^2}\right)\right|_{q=1}\tag{5}\\ &=[t^n]\left(t^2+4t^3+(\color {blue}{(4q+15)}t^4+(30q+56)t^5\right.\\ &\qquad\left.\big.+(15q^2+168q+70)t^6+\cdots\big)\right|_{q=1} \end{align*}
Calculation of $P_n$ and $V_n$:
We manually calculate the polynomial $p_n(q)=[t^n]A(t;q)$ from which we can easily deduce $P_n$ and $V_n$.
Comment:
In (6) we use the binomial series expansion.
In (7) we use the binomial identity $\binom{\frac{1}{2}}{j}=\frac{1}{2^{2j-1}}\binom{2j-2}{j-1}\frac{(-1)^{j-1}}{j}$.
In (8) we apply the rule $[t^{p-q}]A(t)=[t^p]t^qA(t)$.
In (9) we select the coefficient of $t^{n-j}$.