A computer system considers a bit string a valid codeword if and only if it does not contain $3$ consecutive zeroes. Thus $010010$ is a valid codeword of length $6$ while $011000$ is not. Let $a_n$ be the number of valid codewords of length $n$.
The problem is to find $a_1, a_2, a_3$.
I have found $a_1 = 2$ as $O$ and $1$ are the only possibilities in binary bit strings. Our lecturer has told us that $a_2 = 4$ and $a_3 = 7$, but I am not able to work out how he got those. I have looked around and haven't been able to break down the source of $4$ and $7$ ... Could someone give me a hint? Thank you in advance.
The total amount of possible codewords with $n$ bits, valid or not, is $2^n$. $3$ consecutive zeroes are invalid. $a_2$ doesn't have enough digits to make that happen, so every possibility must be valid.$$2^2=4$$
For $3$ digits the only invalid codeword is $000$. You need $3$ zeroes to be invalid, and your length is $3$, so they must all be $0$ to be invalid. That eliminates one out of your set of all possible codewords of length $3$. $$2^3-1=7$$