diff options
| -rwxr-xr-x | challenge-005/gustavo-chaves/perl5/ch-2b.pl | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-005/gustavo-chaves/perl5/ch-2b.pl b/challenge-005/gustavo-chaves/perl5/ch-2b.pl new file mode 100755 index 0000000000..2d7ccda737 --- /dev/null +++ b/challenge-005/gustavo-chaves/perl5/ch-2b.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl + +# Write a program to find the sequence of characters that has the most anagrams. + +use 5.026; +use strict; +use autodie; +use warnings; + +my %anagrams; +my $max = 0; + +# Read list of words and classify them by anagrams +while (<>) { + chomp; + my $count = ++$anagrams{join('', sort split //, lc $_)}; + $max = $count if $count > $max; +} + +# Print all sequences of letters with most anagrams +while (my ($key, $words) = each %anagrams) { + say $key if $words == $max; +} |
