aboutsummaryrefslogtreecommitdiff
path: root/challenge-005/lakpatashi/perl/ch-2.pl
blob: 1c6591f1a1e7cc952a0d6a148cc42344c8961e66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/perl

use strict;
use warnings;

#	PART 2
use Data::Dumper;
my %anaCount;
my @wordList = ('abc','aabb','aedccc','aabbcc');

my @max = (0,'');
for my $word (@wordList){
	my %dict;
	++$dict{$_} for split('', $word);
	#print Dumper(\%dict);
	my $deno = 1;
	$deno *= factorial($_) for values %dict;
	my $result = int factorial(length($word)) / $deno;
	@max = ($result,$word) if $result> $max[0];
}
print "word with max anagrams:\n";
print "@max\n";
sub factorial {
    my ($n) = @_;
	$n *= $_ for 2 .. $n - 1;
	return $n
}