Cupidvogel 0 Newbie Poster

Hi, a program requires one to enter a given number of strings, and for each string, the program has to output the number of permutations possible. We all know that if a string S of length l has a type of one letter, b type of another, c type of another, and so on, while the rest are present only once, then the answer will be (l!)/(a! * b! * c!). Line no. 8 calculates the denominator. Now the question is, can this be made more efficient in any possible way???

use bignum;
sub fact { $_[0] == 0 ? 1 : $_[0]*fact($_[0] - 1); }
chomp($count = <STDIN>);
for (1..$count) {
%hash = ();
$div = 1;
chomp($_ = <STDIN>);
$div *= 1+$hash{$_}++ for split //;
$init = fact(length($_))/$div;
print "$init\n"
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.