Counting words with constraints is the topic of the problem in this note.

penn_teller.pdf