Even A Odd B

An alphabet with two letters A A and B B has two rules for creating words:

1. 1. Any A A must be part of a string containing an even number of A A 's.

2. 2. Any B B must be part of a string of containing an odd number of B B 's.

For example, two six-letter words could be B B B A A B BBBAAB and A A A A A A AAAAAA but A B A B B B ABABBB would not be valid.

How many valid 20 20 letter words ending in B B are there?


The answer is 1035.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Jeremy Galvagni
Jun 13, 2018

W ( n , A ) W(n,A) represents the number of n n letter words ending with A A , W ( n , B ) W(n,B) likewise. W ( n ) = ( X , Y ) W(n)=(X,Y) where X = W ( n , A ) X=W(n,A) , Y = W ( n , B ) Y=W(n,B)

Some small words: W ( 1 ) = ( 0 , 1 ) W(1)=(0,1) because the only valid word is B B .

W ( 2 ) = ( 1 , 0 ) W(2)=(1,0) because the only valid word is A A AA

W ( 3 ) = ( 1 , 2 W(3)=(1,2 ). Valid words are B A A BAA , A A B AAB , B B B BBB .

One recursive formula: W ( n , A ) = W ( ( n 2 ) , A ) + W ( n 2 ) , B ) W(n,A)=W((n-2),A)+W(n-2),B) because you can add A A AA to the end of any word to make a new word ending in an even number of A A .

Another recursive formula: W ( n , B ) = W ( ( n 2 ) , B ) + W ( n 1 ) , A W(n,B)=W((n-2),B)+W(n-1),A ) because you can add B B BB to the end of a word already ending with an odd number of B B or you can add a single B B to a word ending with A A .

Now we can just make a table to solve

n n A A B B A + B A+B
1 0 1 1
2 1 0 1
3 1 2 3
4 1 1 2
5 3 3 6
6 2 4 6
7 6 5 11
8 6 10 16
9 11 11 22
10 16 21 37
11 22 27 49
12 37 43 80
13 49 64 113
14 80 92 172
15 113 144 257
16 172 205 377
17 257 316 573
18 377 462 839
19 573 693 1266
20 839 1035 \boxed{1035} 1874

Incidentally, the A + B A+B column is this sequence so an alternate way of solving is to take a ( 20 ) a ( 18 ) = 1874 839 = 1035 a(20)-a(18)=1874-839=\boxed{1035}

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...