Math problem from logical game

119 Views Asked by At

We have a set of arrows and can start from any point. Every next point must be chosen in direction of previous and can be used only one time. We need to visit all points. Direction of last point doesn't matter. $$\begin{bmatrix} \rightarrow&\leftarrow&\downarrow&\leftarrow\\ \downarrow&\downarrow&\leftarrow&\downarrow\\ \rightarrow&\leftarrow&\uparrow&\uparrow\\ \rightarrow&\uparrow&\leftarrow&\uparrow\\ \end{bmatrix}$$ If make numeration $$\begin{bmatrix} 1&2&3&4\\ 5&6&7&8\\ 9&10&11&12\\ 13&14&15&16\\ \end{bmatrix}$$ the creator of game gives the solution: 1,3,15,14,6,10,9,11,7,5,13,16,8,12,4,2.

So if $a$ length of the row and $b$ length of column, we can make two similar function.

First function $S(a,b)$ count:

  1. Quantity of different sets, which have at least one start point that have solution - $S_{0}(a,b)$.
  2. Summary quantity of different start points in those sets - $S(a,b)$.
  3. Summary quantity of different (for each start point) directions from start to last point (start and last point can be same, but have two or more different directions) - $S_{v}(a,b)$.

So for $b=1$ and

  1. $a=1$ we have: $\begin{bmatrix} \rightarrow\\ \end{bmatrix}$(1), $\begin{bmatrix} \leftarrow\\ \end{bmatrix}$(1), $\begin{bmatrix} \uparrow\\ \end{bmatrix}$(1), $\begin{bmatrix} \downarrow\\ \end{bmatrix}$(1).
  2. $a=2$ we have: $\begin{bmatrix} \rightarrow\color{red}{\rightarrow}\\ \end{bmatrix}$(12), $\begin{bmatrix} \rightarrow\color{red}{\uparrow}\\ \end{bmatrix}$(12), $\begin{bmatrix} \rightarrow\color{red}{\downarrow}\\ \end{bmatrix}$(12), $\begin{bmatrix} \rightarrow\leftarrow\\ \end{bmatrix}$(12,21), $\begin{bmatrix} \color{red}{\leftarrow}\leftarrow\\ \end{bmatrix}$(21), $\begin{bmatrix} \color{red}{\uparrow}\leftarrow\\ \end{bmatrix}$(21), $\begin{bmatrix} \color{red}{\downarrow}\leftarrow\\ \end{bmatrix}$(21).
  3. $a=3$ we have $\begin{bmatrix} \rightarrow\color{red}{\rightarrow\rightarrow}\\ \end{bmatrix}$(123), $\begin{bmatrix} \rightarrow\color{red}{\rightarrow\uparrow}\\ \end{bmatrix}$(123), $\begin{bmatrix} \rightarrow\color{red}{\rightarrow\downarrow}\\ \end{bmatrix}$(123), $\begin{bmatrix} \rightarrow\rightarrow\leftarrow\\ \end{bmatrix}$(123,132,312,231), $\begin{bmatrix} \rightarrow\color{red}{\uparrow}\leftarrow\\ \end{bmatrix}$(132,231), $\begin{bmatrix} \rightarrow\color{red}{\downarrow}\leftarrow\\ \end{bmatrix}$(132,231), $\begin{bmatrix} \color{red}{\rightarrow}\leftarrow\color{red}{\rightarrow}\\ \end{bmatrix}$(213), $\begin{bmatrix} \color{red}{\rightarrow}\leftarrow\color{red}{\uparrow}\\ \end{bmatrix}$(213), $\begin{bmatrix} \color{red}{\rightarrow}\leftarrow\color{red}{\downarrow}\\ \end{bmatrix}$(213), $\begin{bmatrix} \rightarrow\leftarrow\leftarrow\\ \end{bmatrix}$(132,213,231,321), $\begin{bmatrix} \color{red}{\leftarrow}\rightarrow\color{red}{\leftarrow}\\ \end{bmatrix}$(312), $\begin{bmatrix} \color{red}{\uparrow}\rightarrow\color{red}{\leftarrow}\\ \end{bmatrix}$(312), $\begin{bmatrix} \color{red}{\downarrow}\rightarrow\color{red}{\leftarrow}\\ \end{bmatrix}$(312), $\begin{bmatrix} \color{red}{\leftarrow}\color{red}{\leftarrow}\leftarrow\\ \end{bmatrix}$(321), $\begin{bmatrix} \color{red}{\uparrow}\color{red}{\leftarrow}\leftarrow\\ \end{bmatrix}$(321), $\begin{bmatrix} \color{red}{\downarrow}\color{red}{\leftarrow}\leftarrow\\ \end{bmatrix}$(321).

Second function $F(a,b)$ count:

  1. Quantity of different sets, which have at least one start point that have solution for chosen last point (which have undefined direction) - $F_{0}(a,b)$.
  2. Summary quantity of different start points in those sets - $F(a,b)$.
  3. Summary quantity of different (for each start point) directions from start to last point (start and last point can be same, but have two or more different directions) - $F_{v}(a,b)$.

So for $b=1$ and

  1. $a=1$ we have $\begin{bmatrix} 0\\ \end{bmatrix}$(1).
  2. $a=2$ we have $\begin{bmatrix} \rightarrow0\\ \end{bmatrix}$(12), $\begin{bmatrix} 0\leftarrow\\ \end{bmatrix}$(21).
  3. $a=3$ we have $\begin{bmatrix} \rightarrow\color{red}{\rightarrow}0\\ \end{bmatrix}$(123), $\begin{bmatrix} \color{red}{\rightarrow}\leftarrow0\\ \end{bmatrix}$(213), $\begin{bmatrix} 0\rightarrow\color{red}{\leftarrow}\\ \end{bmatrix}$(312), $\begin{bmatrix} \rightarrow0\leftarrow\\ \end{bmatrix}$(132,231), $\begin{bmatrix} 0\color{red}{\leftarrow}\leftarrow\\ \end{bmatrix}$(321).

This function use sets with length $a-1$ from special function $T(a,b)$ with adding undefined last point. Then we put to this undefined point $\uparrow$ and $\downarrow$ (in our case, because $b=1$), but if we put $\rightarrow$ and $\leftarrow$ it special case, which we count with $T(a,b)$. Another words, $S(a,b)=T(a,b)+2F(a,b)$.

We can be sure, that for $n>1$

$$S_{0}(1,n)=S_{0}(n,1)=(n+5)2^{n-2}$$ $$S(1,n)=S(n,1)=(n-2)(n+4)2^{n-2}+8$$ $$S_{v}(1,n)=S_{v}(n,1)=4\cdot n!$$

and

$$F_{0}(1,n)=F_{0}(n,1)=(n+2)2^{n-3}$$ $$F(1,n)=F(n,1)=(n-2)(n+1)2^{n-3}+2$$ $$F_{v}(1,n)=F_{v}(n,1)=n!$$

Also

$$S_{0}(1,1)=S(1,1)=S_{v}(1,1)=4$$ $$F_{0}(1,1)=F(1,1)=F_{v}(1,1)=1$$

How can I find it for any $a,b$?