Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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$.

share|improve this answer
    
+1: This should make it easy to actually write a program. –  Aryabhata Mar 2 '11 at 19:02
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.