diff options
| -rw-r--r-- | challenge-005/fjwhittle/perl6/ch-1.p6 | 17 |
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; |
