From eae3f2b5f54933c6b52888ca3521a13b90e9e3c3 Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Wed, 17 Apr 2019 01:26:42 +1000 Subject: Add Challenge 004.2 solution --- challenge-004/fjwhittle/perl6/ch-2.p6 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 challenge-004/fjwhittle/perl6/ch-2.p6 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; -- cgit