From c045d66d1af0613e7600a448df9a2e2aaf884961 Mon Sep 17 00:00:00 2001 From: "Gustavo L. de M. Chaves" Date: Tue, 23 Apr 2019 21:27:11 -0300 Subject: Another solution to PWC 005 The ch-2b.pl script is shorter, faster, and uses no modules. --- challenge-005/gustavo-chaves/perl5/ch-2b.pl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 challenge-005/gustavo-chaves/perl5/ch-2b.pl 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; +} -- cgit