aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancis Whittle <FJ.Whittle@gmail.com>2019-04-22 12:35:47 +1000
committerFrancis Whittle <FJ.Whittle@gmail.com>2019-04-22 12:35:47 +1000
commitc6325f49e06c4ad11136874faac18e2dcd3eeddf (patch)
treef3d2e1d39f742874cf28245da06532c50e16d94c
parent9193f6efa6b1c5627818ae70b22bca942934d9b1 (diff)
downloadperlweeklychallenge-club-c6325f49e06c4ad11136874faac18e2dcd3eeddf.tar.gz
perlweeklychallenge-club-c6325f49e06c4ad11136874faac18e2dcd3eeddf.tar.bz2
perlweeklychallenge-club-c6325f49e06c4ad11136874faac18e2dcd3eeddf.zip
Week 5 Challenge 1 solution
-rw-r--r--challenge-005/fjwhittle/perl6/ch-1.p617
1 files changed, 17 insertions, 0 deletions
diff --git a/challenge-005/fjwhittle/perl6/ch-1.p6 b/challenge-005/fjwhittle/perl6/ch-1.p6
new file mode 100644
index 0000000000..ffee42f289
--- /dev/null
+++ b/challenge-005/fjwhittle/perl6/ch-1.p6
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+#| Find anagrams of a word in given file
+unit sub MAIN(
+ Str $file #= file containing list of words
+ where { given .IO { .r && ( .l || .f) or die "Cannot read from $_" } },
+ $word #= word to find anagrams of
+);
+
+my $word-bag := $word.lc.comb(/ \w /).Bag;
+
+my @words = $file.IO.lines.unique.hyper.grep(*.chars > 2)
+ .map: { .lc.comb(/ \w /).Bag => $_ };
+
+@words.race.grep(*.key === $word-bag)ยป.value.unique(with => *.lc eq *.lc).join(', ').put;