diff options
| -rw-r--r-- | challenge-004/fjwhittle/perl6/ch-2.p6 | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/challenge-004/fjwhittle/perl6/ch-2.p6 b/challenge-004/fjwhittle/perl6/ch-2.p6 new file mode 100644 index 0000000000..6ffc0f97d3 --- /dev/null +++ b/challenge-004/fjwhittle/perl6/ch-2.p6 @@ -0,0 +1,17 @@ +#!/usr/bin/env perl6 + +use v6; + +#| Find words in a file that contain only the given letters +unit sub MAIN( + Str $file #= file containing list of words + where { given .IO { .r && ( .l || .f) or die "Cannot read from $_" } }, + *@letters #= list of letters to search for +); + +my $letter-bag := @letters.hyper.map(*.lc.comb(/ \w /)).flat.Bag; + +my @words = $file.IO.lines.unique.hyper.grep(*.chars > 2) + .map: { .lc.comb(/ \w /).Bag => $_ }; + +@words.hyper.grep(*.key ⊆ $letter-bag)».value.unique(with => *.lc eq *.lc).join(', ').put; |
