I am trying to write a general formula for the probability of rolling/flipping a $k$-sided object $n$ times and having at least one occurrence of at least $q$ consecutive identical rolls/flips.
This began as an attempt to work out the probability of flipping a coin ten times and having at least one run of three or more identical flips.
In this example case, it is easy to determine the total number of possible outcomes with 10 coin flips -- $2^{10}$. What is not so easy is finding a simple way to count the number of favorable outcomes.
For instance, if you start by counting the number of flips with the first three being heads (HHH???????), there are $2^7$ possibilities. There are also $2^7$ possibilities for TTT???????.
The next few are not too difficult either. For ?HHH?????? there are also $2^7$ possibilities, minus the $2^6$ possibilities you've already counted in the format HHHH??????. The same goes for tails.
The further you go down the line, the trickier it is to subtract the combinations you've already counted, especially when you get to ???HHH????, because then you've already counted possibilities of the type HHHHHH????, ?HHHHH????, ??HHHH????, but also possibilities of type TTTHHH????. The further you go down the line from there, it gets even more complicated keeping track of what you've already counted.
Is there a simpler way to do this than trial and error, and can it be generalized to a formula (as my question asked) for any k-sided object, any number of flips/rolls, and any length of run?
I would like to see how this formula is arrived at, not just what the formula is. NOTE: I am very adept at understanding mathematical concepts, but vocabulary-wise I am not beyond basic self-taught calculus and high school advanced math. Thus I can track with you on a complex explanation as long as you explain (or perhaps link to explanations for) any foreign terms along the way.
Let me just give you some pointers to get started. I haven't worked this out, so I don't know if you'll find a "nice" formula, but I can tell you that there's a better way than what you've been doing.
Precisely because of the difficulties with inclusion and exclusion that you've encountered, it's easier to count the sequences than do not have a run of $q$ identical outcomes. Call a sequence "good" if no run of $q$ identical outcomes occurs in it. Let $S_j^{(n)}$ be the number of good sequences of length $n$ than end in a maximal run of $j$ identical outcomes. For example, $S_3^{(10)}$ is the number of sequences of length $10$ that end in a run of $3$ identical outcomes, but not $4$ identical outcomes. Define $$S^{(n)}=\sum_{j=1}^{q-1}S_j^{(n)}$$ so that it is $S^{(n)}$ that we want to compute.
We have $$ \begin{align} S_1^{(1)}&=k\\ S_j^{(1)}&=0,\ j>1\\ S_j^{(n)}&=S_{j-1}^{(n-1)}, 1<j<q\\ S_1^{(n)}&=(k-1)S^{(n-1)} \end{align} $$
The first two equations are clear.
For the third equation, note that a good sequence of length $n$ that ends in a run of $j>1$ can only arise from a good sequence of length $n-1$ that ends in a run of $j-1;$ of course, the next outcome must be the same a the one in the run, so it can only arise in one way.
For the fourth equation, a good sequence of length $n$ ending in a run of exactly $1$ arises from a good any sequence of length $n-1$ followed by any of the $k-1$ outcomes that is different from the last outcome of that sequence.
For given values of $n,k,q$ this allows you to work out the value of $S^{(n)}$ quickly, especially if you use a computer. Then you just need to divide by $k^n,$ and subtract from $1.$
I suggest you try working out examples with $q=2$ and small values of $k$ to begin with, and see if you find any patterns.
Good luck.
EDIT
Corrected a typo. There are $k^n$ possible sequences of length $n$ of course, not $q^n$.