aboutsummaryrefslogtreecommitdiff
path: root/challenge-005
diff options
context:
space:
mode:
authorFrancis Whittle <FJ.Whittle@gmail.com>2019-04-22 15:34:30 +1000
committerFrancis Whittle <FJ.Whittle@gmail.com>2019-04-22 16:18:40 +1000
commit8b452eba2700aadc92dbdb3ec55851fbac7e4fc4 (patch)
treef39366e2d2fc311a40ccb778d94a840f5c395506 /challenge-005
parentc6325f49e06c4ad11136874faac18e2dcd3eeddf (diff)
downloadperlweeklychallenge-club-8b452eba2700aadc92dbdb3ec55851fbac7e4fc4.tar.gz
perlweeklychallenge-club-8b452eba2700aadc92dbdb3ec55851fbac7e4fc4.tar.bz2
perlweeklychallenge-club-8b452eba2700aadc92dbdb3ec55851fbac7e4fc4.zip
Week 5 Challenge 2 solution
Diffstat (limited to 'challenge-005')
-rw-r--r--challenge-005/fjwhittle/perl6/ch-2.p619
1 files changed, 19 insertions, 0 deletions
diff --git a/challenge-005/fjwhittle/perl6/ch-2.p6 b/challenge-005/fjwhittle/perl6/ch-2.p6
new file mode 100644
index 0000000000..75cdfa6a55
--- /dev/null
+++ b/challenge-005/fjwhittle/perl6/ch-2.p6
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+#| Find the sequence of letters with the most anagrams in a given file
+unit sub MAIN(
+ IO(Str) $file #= file containing list of words
+ where { given .IO { .r && ( .l || .f) or die "Cannot read from $_" } };
+);
+
+my SetHash %sequences{Str};
+
+for $file.lines -> $word {
+ my $seq = $word.lc.comb(/\w/).sort.join(',') and %sequences{$seq}{$word.lc}++;
+}
+
+my $maxwords = %sequences.values».elems.max;
+
+.fmt('%1$s(%2$d): %2$s').say for %sequences.pairs.grep: *.value.elems == $maxwords