Given an alphabet of 3 letters i.e. a,b,c evaluate
the number of n-letter words containing even number
of “a”s.
Within each n, for every even value, i, of number of a's that is less than or equal to n, the placement of the a's can be done in C(n,i) ways where i is the number of a's. For each of these, the remaining n-i letters can be either b or c, so C(n,i) needs to be multiplied by 2^(n-i).
Sigma{even i <=n} C(n,i)*2^(n-i)
clearvars, clc
for n=2:25
tot=0;
for i=2:2:n
tot=tot+nchoosek(n,i)*2^(n-i);
end
fprintf('%2d %15d\n',n,tot);
end
count of number of
a's such "words"
2 1 aa: a type of lava
3 6 baa, caa, aba, aca, aab, aac
4 25
5 90
6 301
7 966 etc.
8 3025
9 9330
10 28501
11 86526
12 261625
13 788970
14 2375101
15 7141686
16 21457825
17 64439010
18 193448101
19 580606446
20 1742343625
21 5228079450
22 15686335501
23 47063200806
24 141197991025
25 423610750290
|
Posted by Charlie
on 2022-04-27 08:36:49 |