lock pattern possibilities when starting from corner only

166 Views Asked by At

Smartphone lock pattern is a route of length n in a 3x3 grid. In every step it is allowed to move from one point to any of the other near points, including in diagonal and including already visited points. Find an explicit expression to the number of patterns of length n starting from a corner (find and solve a recursive equation).

What I did: I thought to start from a corner (4 options) and moving to any near point (5 options). So far I've made one move and I'm necessarily in a "non-corner" point. Now if I move back to a "corner point" (4 options) I've made 2 moves so I wrote: $$f(n)=80\cdot f(n-2)$$

but I don't know how to express the posibility of not going back to a "corner point" in the second move.

edit: one can 5 movees from a given corner cell (3 trivial moves and 2 diagonal moves as can be seen here: enter image description here

1

There are 1 best solutions below

10
On BEST ANSWER

To start out, use a linked recursion . . .

  • Let $f(n)$ be the number of paths of length $n$, starting from a corner vertex.$\\[4pt]$
  • Let $g(n)$ be the number of paths of length $n$, starting from a non-corner edge vertex.$\\[4pt]$
  • Let $h(n)$ be the number of paths of length $n$, starting from the center vetex.

By considering what happens in one move, we get the linked recursion \begin{align*} f(n)&=4g(n-1)+h(n-1)\tag{eq1}\\[4pt] g(n)&=4f(n-1)+2g(n-1)+h(n-1)\tag{eq2}\\[4pt] h(n)&=4f(n-1)+4g(n-1)\tag{eq3}\\[4pt] \end{align*} with initial conditions $f(0) = g(0) = h(0) = 1$.

As a sample, here are a few values . . . $$\begin{array}{c|c|c|c|} n&f(n)&g(n)&h(n)\\ \hline 0&1&1&1\\ \hline 1&5&7&8\\ \hline 2&36&42&48\\ \hline 3&216&276&312\\ \hline 4&1416&1728&1968\\ \hline 5&8880&11088&12576\\ \hline 6&56928&70272&79872\\ \hline \end{array} $$

Next, we unlink the recursion . . .

Assume $n > 1$.

From $(\text{eq}3)$, we get $$h(n-1) = 4f(n - 2) + 4g(n - 2)\tag{eq4}$$ Using $(\text{eq}4)$ to replace $h(n-1)$ in $(\text{eq}1)$, we get $$f(n)=4g(n-1)+4f(n-2)+4g(n-2)\tag{eq5}$$ Using $(\text{eq}4)$ to replace $h(n-1)$ in $(\text{eq}2)$, we get $$g(n)=4f(n-1)+2g(n-1)+ 4f(n-2)+4g(n-2)\tag{eq6}$$ Subtracting $(\text{eq}6)$ from $(\text{eq}5)$, we get $$f(n)-g(n)=2g(n-1)-4f(n-1)\tag{eq7}$$ From $(\text{eq}5)$, we get $$f(n+1)=4g(n)+4f(n-1)+4g(n-1)\tag{eq8}$$ Subtracting $(\text{eq}8)$ from twice $(\text{eq}7)$, we get $$g(n)=-f(n)+{\small{\frac{1}{2}}}f(n+1)-6f(n-1)\tag{eq9}$$ From $(\text{eq}9)$, we get $$g(n-1)=-f(n-1)+{\small{\frac{1}{2}}}f(n)-6f(n-2)\tag{eq10}$$ Using $(\text{eq}9)$ and $(\text{eq}10)$ to replace $g(n)$ and $g(n-1)$ in $(\text{eq}8)$, and then solving for $f(n+1)$, we get $$f(n+1)=2f(n)+24f(n-1)+24f(n-2)\tag{eq11}$$ We have $f(0)=1$, and from the linked recursion, we have $f(1)=5$, and $f(2)=36$, hence $f$ satisfies the recurrence $$ f(n)= \begin{cases} 1&\text{if}\;n=0\\[4pt] 5&\text{if}\;n=1\\[4pt] 36&\text{if}\;n=2\\[4pt] 2f(n-1)+24f(n-2)+24f(n-3)\;\;\;&\text{if}\;n>2\\ \end{cases} $$ That's assuming we start from a fixed corner vertex.

If we allow starting from any of the $4$ corner vertices, the answer is just $4f(n)$.

The recurrence for $f$ is a third-order linear recurrence with constant coefficients.

The corresponding characteristic polynomial is $$x^3-2x^2-24x-24$$ which has $3$ real irrational roots $r,s,t$ with approximate values \begin{align*} r&\approx -3.176727981\\[4pt] s&\approx -1.187158691\\[4pt] t&\approx 6.363886672\\[4pt] \end{align*} Then $f(n)$ is equal to $$f(n)=ar^n+bs^n+ct^n$$ where $a,b,c$ are real irrational numbers with approximate values $$ \begin{align*} a&\approx .1349412775\\[4pt] b&\approx .01012627238\\[4pt] c&\approx .8549324501\\[4pt] \end{align*} $$