aboutsummaryrefslogtreecommitdiff
path: root/challenge-005
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2019-04-22 10:27:23 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2019-04-22 10:27:23 +0100
commit8c48dbb64b97b7bb441882f683e4044e90d0c128 (patch)
treeff9679303900e11605ac653e9cd6bfedc78495cf /challenge-005
parent9924f5871e0879c3268b831707c1906458bac3bd (diff)
parent8954652ed5a3751c0547b2413c866380842e03d1 (diff)
downloadperlweeklychallenge-club-8c48dbb64b97b7bb441882f683e4044e90d0c128.tar.gz
perlweeklychallenge-club-8c48dbb64b97b7bb441882f683e4044e90d0c128.tar.bz2
perlweeklychallenge-club-8c48dbb64b97b7bb441882f683e4044e90d0c128.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-005')
-rw-r--r--challenge-005/fjwhittle/blog.txt1
-rw-r--r--challenge-005/fjwhittle/perl6/ch-1.p617
-rw-r--r--challenge-005/fjwhittle/perl6/ch-2.p619
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