2026-07-08

Problem — 2026-07-08

Medium

MediumNumber theory

A cryptographer designs a secret knock pattern using exactly 20 knocks. Each knock must be either soft (S) or loud (L). The security rule requires that no two consecutive loud knocks can occur anywhere in the pattern. How many valid knock patterns exist?

Enter the exact number of valid patterns

Show solution
Let ana_n denote the number of valid knock patterns of length nn. We can build any valid pattern of length nn by considering what happens at the end: - If the pattern ends with S (soft knock), the first n−1n-1 knocks can be any valid pattern of length n−1n-1. This gives an−1a_{n-1} possibilities. - If the pattern ends with L (loud knock), the (n−1)(n-1)-th knock must be S (to avoid consecutive loud knocks). So the pattern ends with "...SL", and the first n−2n-2 knocks can be any valid pattern of length n−2n-2. This gives an−2a_{n-2} possibilities. Therefore, we have the recurrence relation: a_n = a_{n-1} + a_{n-2} For base cases: - a1=2a_1 = 2 (either S or L) - a2=3a_2 = 3 (SS, SL, or LS; note LL is forbidden) This is the Fibonacci recurrence! Specifically, an=Fn+2a_n = F_{n+2} where FnF_n is the nn-th Fibonacci number with F1=F2=1F_1 = F_2 = 1. Computing: - a1=2=F3a_1 = 2 = F_3 - a2=3=F4a_2 = 3 = F_4 - a3=5=F5a_3 = 5 = F_5 - a4=8=F6a_4 = 8 = F_6 - a5=13=F7a_5 = 13 = F_7 - a6=21=F8a_6 = 21 = F_8 - a7=34=F9a_7 = 34 = F_9 - a8=55=F10a_8 = 55 = F_{10} - a9=89=F11a_9 = 89 = F_{11} - a10=144=F12a_{10} = 144 = F_{12} - a11=233=F13a_{11} = 233 = F_{13} - a12=377=F14a_{12} = 377 = F_{14} - a13=610=F15a_{13} = 610 = F_{15} - a14=987=F16a_{14} = 987 = F_{16} - a15=1597=F17a_{15} = 1597 = F_{17} - a16=2584=F18a_{16} = 2584 = F_{18} - a17=4181=F19a_{17} = 4181 = F_{19} - a18=6765=F20a_{18} = 6765 = F_{20} - a19=10946=F21a_{19} = 10946 = F_{21} - a20=17711=F22a_{20} = 17711 = F_{22} Therefore, the answer is a20=F22=10946a_{20} = F_{22} = \boxed{10946}.