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.