So I know the theory behind finding anagrams, shown here. For my purposes I need to find the amount of anagrams that can be found from a word excluding duplicates.
Allowing for duplicates, this is fairly simple.
aab
has the following anagrams:
aab
aab
aba
aba
baa
baa
This amount can be found by calculating the factorial from the amount of letters
factorial := 1
for i := len(word); i > 0; i-- {
factorial = i * factorial
}
// aab -> 6
However, if you want to exclude duplicates you have reduced your potential anagrams from 6 to 3. An example of this is the word hello
, which has 120 combinations, yet only 60 without duplicates.
I coded my own algorithm that made a map of letters and returned the length of the map, but this had issues as well.
hello -> 24 (actually 60)
helllo -> 24 (actually 120)
How can I accomplish this?