From c6325f49e06c4ad11136874faac18e2dcd3eeddf Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Mon, 22 Apr 2019 12:35:47 +1000 Subject: Week 5 Challenge 1 solution --- challenge-005/fjwhittle/perl6/ch-1.p6 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 challenge-005/fjwhittle/perl6/ch-1.p6 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; -- cgit