Quick Elementary Combinatorics Question / Verification

Click For Summary
The discussion revolves around calculating the number of valid variable names in a programming language based on specific character rules. For exactly 5 characters, there are 834,906,933 possible names, derived from 53 options for the first character and 63 for the remaining four. When considering names with at most 5 characters, the total rises to 848,373,173. For palindromic names (those that read the same forwards and backwards), the total is 217,141. The calculations presented in the thread are confirmed to be accurate.
tylerc1991
Messages
158
Reaction score
0

Homework Statement



I am using a book that doesn't have any solutions in it, so I would like to be sure that I am doing the problems right before I move on. The question is below:

In a programming language, a variable name must start with a letter or the underscore character, and succeeding characters must be letters, digits, or the underscore character. Uppercase and lowercase letters are considered different.
(a) How many variable names with exactly 5 characters can be formed?
(b) How many are there with at most 5 characters?
(c) How many are there with at most 5 characters, if they must read the same forwards and backwards? (note that kayak is acceptable but Kayak is not).

The Attempt at a Solution


(a) There are 53 possible characters for the first position, and 63 possibilities for the remaining 4 positions. So there are
53 \cdot 63^4 = 834,906,933
possible 5 character variable names.

(b) For some k, there are 53 \cdot 63^{k-1} possible variable names of length k. So the number of possible variable names with length at most 5 is
\sum_{k=1}^5 53 \cdot 63^{k-1} = 848,373,173 possible variable names with length at most 5.

(c) For length 1, there are only 53 such possible variable names. For length 2, the first and last characters must be the same, so there are again only 53 such possible variable names. For length 3, there are 53 * 63 variable names, and the same number of variable names of length 4. For length 5, there are 53 * 63 * 63 possible variable names. Hence, there are
53 + 53 + 53 \cdot 63 + 53 \cdot 63 + 53 \cdot 63^2 = 217,141
possible variable names with the desired property.

Thanks!
 
Physics news on Phys.org
tylerc1991 said:

Homework Statement



I am using a book that doesn't have any solutions in it, so I would like to be sure that I am doing the problems right before I move on. The question is below:

In a programming language, a variable name must start with a letter or the underscore character, and succeeding characters must be letters, digits, or the underscore character. Uppercase and lowercase letters are considered different.
(a) How many variable names with exactly 5 characters can be formed?
(b) How many are there with at most 5 characters?
(c) How many are there with at most 5 characters, if they must read the same forwards and backwards? (note that kayak is acceptable but Kayak is not).

The Attempt at a Solution


(a) There are 53 possible characters for the first position, and 63 possibilities for the remaining 4 positions. So there are
53 \cdot 63^4 = 834,906,933
possible 5 character variable names.

(b) For some k, there are 53 \cdot 63^{k-1} possible variable names of length k. So the number of possible variable names with length at most 5 is
\sum_{k=1}^5 53 \cdot 63^{k-1} = 848,373,173 possible variable names with length at most 5.

(c) For length 1, there are only 53 such possible variable names. For length 2, the first and last characters must be the same, so there are again only 53 such possible variable names. For length 3, there are 53 * 63 variable names, and the same number of variable names of length 4. For length 5, there are 53 * 63 * 63 possible variable names. Hence, there are
53 + 53 + 53 \cdot 63 + 53 \cdot 63 + 53 \cdot 63^2 = 217,141
possible variable names with the desired property.

Thanks!

Your calculations look correct to me.
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
3
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K