53.7k views
5 votes
Amy writes a computer program that will choose two letters from her name to make a two letter "string".The order of the letters. For example,AM and MA are different strings

List all the possible outcomes for forming a two letter string?

User Ustulation
by
5.7k points

2 Answers

4 votes
Var arr = []

For (i = 0; i < 26; i++) {
For (j = 0; j < 26; j++) {
Console.log(arr.join([i][j]));
}
}

Along these lines but converting i and j to the ASCII letter based on number.. example 0=a 1=b 2=c...
User MinTwin
by
6.0k points
4 votes
The lists are
AM
MA
AY
YA
MY
YM
Are the six ways that these can be listed. There are 6 altogether.
If you know what the counting principle is you can do it this way.

The first letter is any choice 3
The second letter can be one of 2
The number of ways of doing this problem is 3*2 = 6

However the question does not make clear if duplicates are allowed. We are only told that the string consists of 2 letters. They could be the same. In that case you have three more answers.

AA
MM
YY

I think the answer is intended to be 6, but it could be 9.
Use 6.<<< Answer
But don't be surprised if 9 is correct.
User Urb
by
5.3k points