diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-04-28 18:42:42 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-04-28 18:42:42 +0100 |
| commit | 6eaab4c8fcac78775197a878a141adfdd678c7d5 (patch) | |
| tree | db9bc53d592d60f83223759cdc9ca5b7b60fc1b4 /challenge-005 | |
| parent | 5697f30837ae971ebbdf7d9fdaeb3a65234ba673 (diff) | |
| download | perlweeklychallenge-club-6eaab4c8fcac78775197a878a141adfdd678c7d5.tar.gz perlweeklychallenge-club-6eaab4c8fcac78775197a878a141adfdd678c7d5.tar.bz2 perlweeklychallenge-club-6eaab4c8fcac78775197a878a141adfdd678c7d5.zip | |
- Added solutions by Jo Christian Oterhals.
Diffstat (limited to 'challenge-005')
| -rw-r--r-- | challenge-005/jo-christian-oterhals/perl6/ch-1.p6 | 4 | ||||
| -rw-r--r-- | challenge-005/jo-christian-oterhals/perl6/ch-2.p6 | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/challenge-005/jo-christian-oterhals/perl6/ch-1.p6 b/challenge-005/jo-christian-oterhals/perl6/ch-1.p6 new file mode 100644 index 0000000000..e6b218f753 --- /dev/null +++ b/challenge-005/jo-christian-oterhals/perl6/ch-1.p6 @@ -0,0 +1,4 @@ +my $dict = "/usr/share/dict/words".IO.lines()>>.lc.Set; +for @*ARGS ?? @*ARGS !! ! $*IN.t ?? lines() !! '' -> $w { + $w.lc.comb.permutations>>.join.grep({ $dict{$_} and $_ ne $w }).map({ "$w\t$_\n" }).unique.join.say; +} diff --git a/challenge-005/jo-christian-oterhals/perl6/ch-2.p6 b/challenge-005/jo-christian-oterhals/perl6/ch-2.p6 new file mode 100644 index 0000000000..939c06cb95 --- /dev/null +++ b/challenge-005/jo-christian-oterhals/perl6/ch-2.p6 @@ -0,0 +1,10 @@ +my %dict = "/usr/share/dict/words".IO.lines().map({ $_.lc => True}); +my %rev-dict; +push %rev-dict{$_.comb.sort.join}, $_ for %dict.keys; +my @variation = reverse + sort { %rev-dict{$_}.elems }, %rev-dict.keys; +my $max-anagrams = %rev-dict{@variation[0]}.elems; +for @variation { + last if %rev-dict{$_}.elems != $max-anagrams; + say "$_ ($max-anagrams): " ~ %rev-dict{$_}.join(','); +} |
