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 an denote the number of valid knock patterns of length n.
We can build any valid pattern of length n by considering what happens at the end:
- If the pattern ends with S (soft knock), the first n−1 knocks can be any valid pattern of length n−1. This gives an−1 possibilities.
- If the pattern ends with L (loud knock), the (n−1)-th knock must be S (to avoid consecutive loud knocks). So the pattern ends with "...SL", and the first n−2 knocks can be any valid pattern of length n−2. This gives an−2 possibilities.
Therefore, we have the recurrence relation:
a_n = a_{n-1} + a_{n-2}
For base cases:
- a1=2 (either S or L)
- a2=3 (SS, SL, or LS; note LL is forbidden)
This is the Fibonacci recurrence! Specifically, an=Fn+2 where Fn is the n-th Fibonacci number with F1=F2=1.
Computing:
- a1=2=F3
- a2=3=F4
- a3=5=F5
- a4=8=F6
- a5=13=F7
- a6=21=F8
- a7=34=F9
- a8=55=F10
- a9=89=F11
- a10=144=F12
- a11=233=F13
- a12=377=F14
- a13=610=F15
- a14=987=F16
- a15=1597=F17
- a16=2584=F18
- a17=4181=F19
- a18=6765=F20
- a19=10946=F21
- a20=17711=F22
Therefore, the answer is a20=F22=10946.