All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Just Math
Counting words (Posted on 2022-04-27) Difficulty: 3 of 5
Given an alphabet of 3 letters i.e. a,b,c evaluate
the number of n-letter words containing even number of “a”s.

No Solution Yet Submitted by Ady TZIDON    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
re: solution -- correction | Comment 3 of 7 |
(In reply to solution by Charlie)

Of course, reading Larry's post reminded me that zero is an even number, so:


clearvars, clc
for n=1:25
  tot=0;
  for i=0:2:n
    tot=tot+nchoosek(n,i)*2^(n-i);
  end
  fprintf('%2d %15d\n',n,tot);
end

 1               2
 2               5
 3              14
 4              41
 5             122
 6             365
 7            1094
 8            3281
 9            9842
10           29525
11           88574
12          265721
13          797162
14         2391485
15         7174454
16        21523361
17        64570082
18       193710245
19       581130734
20      1743392201
21      5230176602
22     15690529805
23     47071589414
24    141214768241
25    423644304722

  Posted by Charlie on 2022-04-27 08:50:11
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (0)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information