# Need a nudge in the right direction - How do I find the total number of permutation with 3 consecutive characters?

Again, I really just want a nudge in the right direction. Possibly a large nudge, but not the straight forward answer.

I am trying to figure out how to solve Project Euler Problem 191.

I believe I have most of it figured out, but I cannot come up with an algorithm or pattern for the 3-consecutive-Absent days part. I can even find the number of permutations of the strings holding the total number of A-days constant (i.e. how many permutations with only 1 A-day, only 2 A-days, only 3 A-days, etc.), but I cannot figure out how many permutations have 3 consecutive A-days.

So, is there a mathematical formula for this? Is there a way to break this up so that I have "(some # permutations) +/- (another # of permutations) = (# of consecutive A-days)"? I believe this is a combinatorial problem, but maybe it falls under a different category.

Any help is appreciated. Thanks.

-

For each string length $n$, you want to keep track of six quantities: the number of good'' (i. e. prize-winning) strings of length $n$ which end in $i$ $A$s ($i = 0, 1, 2$) and contain $j$ $L$s ($j = 0, 1$). These six quantities for strings of length $n+1$ can be simply written in terms of those for length $n$.

-
+1: This should make it easy to actually write a program. – Aryabhata Mar 2 '11 at 19:02

Ignoring the L, you only need to count the number of strings in which the As appear doubly at the most.

To count this, first fix the number of Os and fix the number of As appearing singly (and so by implication the number of AA blocks).

Now write the Os with dashes between them and to left, for instance with 3 Os.

_ O _ O _ O _

You now need to fill some of the dashes with the number of A and AA you chose.

Vary the number of Os and As and add up for the total.

Hope that helps.

-