To block his phone, Tom chooses a path on the phone screen that must pass through the sides of the squares, without passing through the vertices, in a continuous path. In the figure, we have two examples, both starting at 1 and ending at 5.

![](https://cdn.mathpix.com/cropped/2024_05_01_a50b5476db779c3986d5g-13.jpg?height=315&width=304&top_left_y=1413&top_left_x=763)

| 1 | 2 | 3 |
| :--- | :--- | :--- |
| 4 | 5 | 6 |
| 7 | 8 | 9 |

a) How many different passwords, with 3 numbers, can Tom choose?

b) And with all 9 numbers, using each exactly once, how many passwords can Tom choose, starting at 5?
Solution

a) Starting from the corners, there are 4 possibilities for each ( $4 \cdot 4=16$ in total), for example, starting with 1, we have the passwords 123, 125, 145, 147. Starting from 2, 4, 6, or 8, there are 5 possibilities for each ( $4 \cdot 5=20$ in total), for example, starting with 2, we have the passwords 236, 256, 258, 254, 214. Starting from 5, there are 8 possibilities (521, 523, $563, 569, 589, 587, 547, 541$). Thus, we have a total of $16+20+8=44$ passwords with 3 numbers.

b) Starting from 5, the second number must be 2, 4, 6, or 8, and in each case, it must follow the sequence clockwise or counterclockwise. Thus, there are $4 \cdot 2=8$ passwords.