diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-04-22 10:19:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-22 10:19:12 +0100 |
| commit | 8954652ed5a3751c0547b2413c866380842e03d1 (patch) | |
| tree | dd08ced007f812d2e39bafee846da4e85b8f62a5 | |
| parent | 9193f6efa6b1c5627818ae70b22bca942934d9b1 (diff) | |
| parent | 0f012b9d734d64ce45df5b7be4919d328590e5f4 (diff) | |
| download | perlweeklychallenge-club-8954652ed5a3751c0547b2413c866380842e03d1.tar.gz perlweeklychallenge-club-8954652ed5a3751c0547b2413c866380842e03d1.tar.bz2 perlweeklychallenge-club-8954652ed5a3751c0547b2413c866380842e03d1.zip | |
Merge pull request #85 from fjwhittle/master
Francis Whittle week 5 solutions.
| -rw-r--r-- | challenge-005/fjwhittle/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-005/fjwhittle/perl6/ch-1.p6 | 17 | ||||
| -rw-r--r-- | challenge-005/fjwhittle/perl6/ch-2.p6 | 19 |
3 files changed, 37 insertions, 0 deletions
diff --git a/challenge-005/fjwhittle/blog.txt b/challenge-005/fjwhittle/blog.txt new file mode 100644 index 0000000000..afa4b8a4ba --- /dev/null +++ b/challenge-005/fjwhittle/blog.txt @@ -0,0 +1 @@ +https://rage.powered.ninja/2019/04/22/anagramming-max.html 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; diff --git a/challenge-005/fjwhittle/perl6/ch-2.p6 b/challenge-005/fjwhittle/perl6/ch-2.p6 new file mode 100644 index 0000000000..75cdfa6a55 --- /dev/null +++ b/challenge-005/fjwhittle/perl6/ch-2.p6 @@ -0,0 +1,19 @@ +#!/usr/bin/env perl6 + +use v6; + +#| Find the sequence of letters with the most anagrams in a given file +unit sub MAIN( + IO(Str) $file #= file containing list of words + where { given .IO { .r && ( .l || .f) or die "Cannot read from $_" } }; +); + +my SetHash %sequences{Str}; + +for $file.lines -> $word { + my $seq = $word.lc.comb(/\w/).sort.join(',') and %sequences{$seq}{$word.lc}++; +} + +my $maxwords = %sequences.values».elems.max; + +.fmt('%1$s(%2$d): %2$s').say for %sequences.pairs.grep: *.value.elems == $maxwords |
