diff options
| author | Gustavo L. de M. Chaves <gustavo@cpqd.com.br> | 2019-04-23 21:27:11 -0300 |
|---|---|---|
| committer | Gustavo L. de M. Chaves <gustavo@cpqd.com.br> | 2019-04-23 21:27:11 -0300 |
| commit | c045d66d1af0613e7600a448df9a2e2aaf884961 (patch) | |
| tree | fbcac2b915fcad4790cf96cceb683dd61414c3c1 /challenge-005 | |
| parent | 5be2e50c200ff7b0a81ab24bd825e374cc7f231c (diff) | |
| download | perlweeklychallenge-club-c045d66d1af0613e7600a448df9a2e2aaf884961.tar.gz perlweeklychallenge-club-c045d66d1af0613e7600a448df9a2e2aaf884961.tar.bz2 perlweeklychallenge-club-c045d66d1af0613e7600a448df9a2e2aaf884961.zip | |
Another solution to PWC 005
The ch-2b.pl script is shorter, faster, and uses no modules.
Diffstat (limited to 'challenge-005')
| -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; +} |
