Probability of two consecutive elements repeating Let's say we have elements A and P and I want to group these in groups of n. Let's make an example where n is equal to 3 (groups would be AAP, APA, PPA, etc.).
All possible combinations would be 2 to the power of 3 -> 8.
Now, my problem comes because I cannot have the element A twice in a row.
So all combination are AAA, AAP, APA, APP, PAA, PAP, PPA, and PPP, but answers AAA, AAP, and PAA are excluded because A is repeated consecutively.
What kind of algorithm could I use to find the groups where A is repeated so I can exclude them from all possible combinations?
P.S. I have to make this into code, so a code algorithm would be appreciated.
 A: Let $f(n)$, $g(n)$, $h(n)$  be the number of combinations ending in A, ending in P and the total amount of combinations respectively. We have $f(1)=1$; $g(1)=1$; $h(1)=2$; $f(2)=1$; $g(2)=2$; $h(2)=3$. The number of combinations ending in A of $n+1$ must start with a combination ending in P of $n$ and then end with A. Therefore $f(n+1)=g(n)$. The number of combinations ending in P of $n+1$ either start with a combination ending in P of $n$ or start with a combination ending in A of $n$. Therefore $g(n+1)=f(n)+g(n)$. Also clearly $h(n)=g(n)+f(n)$. So $g(n+1)=f(n)+g(n)=g(n)+g(n-1)$ which has the characteristic equation $x^2-x-1=0$. Solving it you get $g(n)=\frac {5+\sqrt5} {10}(\frac {1+\sqrt5} 2)^n+\frac {5-\sqrt5} {10}(\frac {1-\sqrt5} 2)^n$. Also $f(n+1)=g(n)$ so $f(n)= \frac {5+\sqrt5} {10}(\frac {1+\sqrt5} 2)^{n-1}+\frac {5-\sqrt5} {10}(\frac {1-\sqrt5} 2)^{n-1}$. So the number of combinations is $h(n)=\frac {5+\sqrt5} {10}(\frac {1+\sqrt5} 2)^{n-1}+\frac {5-\sqrt5} {10}(\frac {1-\sqrt5} 2)^{n-1}+\frac {5+\sqrt5} {10}(\frac {1+\sqrt5} 2)^n+\frac {5-\sqrt5} {10}(\frac {1-\sqrt5} 2)^n$
