For a given word calculate the number of possible anagrams c#

  • Thread starter Thread starter keeponfalling
  • Start date Start date
K

keeponfalling

Guest
The problem is that, the code is working for small words(char) like = wwwd = 4 anagrams or ccde = 12 anagrams...the problems is with words like this: "abcdefghijklmnoqprstuvwxyzabcdefghijklmnoqprstuvwxyz" I must have 1.20190046982384E+60
and i get :
8.065829222532113E+26. Can you give me a hint please about what I do wrong. Thanks

static void Main(string[] args)
{
string word = Console.ReadLine();
double result = FactorialOfWord(ref word);
double resultTwo = FactorialOfLetters(ref word);
Console.WriteLine(result/resultTwo);


Console.Read();
}

static double FactorialOfWord(ref string word)
{
double firstNumber = 1;
for (int i=1; i<= word.Length; i++)
{
firstNumber *= i;
}
return firstNumber;
}

static double FactorialOfLetters(ref string word)
{
double five = 1;
double secondNumber = 1;
double thirdNumber = 1;
for(int i=0; i < word.Length; i++)
{
for(int j =i+1; j < word.Length; j++)
{
if(word == word[j])
{
five = (secondNumber *= j)+j;

}
if (word != word[j])
{
thirdNumber *= 1;
}
}
}
return five * thirdNumber;
}

Continue reading...
 
Back
Top