How Many 3 letter words from characters in "ABRACADABRA"?

101 Views Asked by At

The words cannot have a repetition of letters and each character of the type is distinct i.e. the first 'B' is distinct from the second 'B', and both the 'B's can not be in a word simultaneously.

I need an algorithm/formula that answers for any word(provided as count of each letter).

for a smaller word: AABBC answers are permutations of these letters:

  1. A1B1C
  2. A1B2C
  3. A2B1C
  4. A2B2C

These are all the combinations.

So count of all words is = 4 * 3P3 = 4 * 6 = 24

2

There are 2 best solutions below

4
On

In your question, the total number of 3 letter groupings which do not repeat a letter will be

{11 /choose 3} - {5/choose2}x(11-3) - {2/choose2}x(11-2) = G (say)

where the second term takes care of excluding the words having atleast 2 A’s and the third term for words having atleast 2 B’s. So, the total words will be G x 3!

You can follow a similar procedure for any word, wherein you’ll have to subtract a term for each repeated letter.

3
On

As an algorithm:

loop over (0-9) as A   
  loop over (0-9 excluding A) as B
    loop over(0-9 excluding B) as C
      output ABC
    end
  end
end

You could try asking this question on stackoverflow as well.