diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-04-22 14:10:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-22 14:10:14 +0100 |
| commit | 08c5c6db5558eaf974a267e2fc73163134202b16 (patch) | |
| tree | f73f2eec4f08131f034a7cd6d50c1d43834b4989 | |
| parent | 863762cb5e270a478f349163b1d466398290157c (diff) | |
| parent | 38a2dd0cc58272e1033b7a5c20c040e0e46404d3 (diff) | |
| download | perlweeklychallenge-club-08c5c6db5558eaf974a267e2fc73163134202b16.tar.gz perlweeklychallenge-club-08c5c6db5558eaf974a267e2fc73163134202b16.tar.bz2 perlweeklychallenge-club-08c5c6db5558eaf974a267e2fc73163134202b16.zip | |
Merge pull request #86 from Rob4t/master
Solution to challenge 005
| -rw-r--r-- | challenge-005/rob4t/perl6/ch-1.p6 | 16 | ||||
| -rw-r--r-- | challenge-005/rob4t/perl6/ch-2.p6 | 11 |
2 files changed, 27 insertions, 0 deletions
diff --git a/challenge-005/rob4t/perl6/ch-1.p6 b/challenge-005/rob4t/perl6/ch-1.p6 new file mode 100644 index 0000000000..d4f5295fbe --- /dev/null +++ b/challenge-005/rob4t/perl6/ch-1.p6 @@ -0,0 +1,16 @@ +#!/usr/bin/env perl6 +use v6; + +sub MAIN(Str $word, Str $file where *.IO.r = '/usr/share/dict/words') { + my $word_bag = $word.lc.comb.Bag; + + my @found_words = $file.IO.lines.grep: { + # not the same word + .lc ne $word.lc + and + # look for words AND phrases + .lc.words.map({.comb}).flat.Bag eqv $word_bag + }; + + .say for @found_words; +} diff --git a/challenge-005/rob4t/perl6/ch-2.p6 b/challenge-005/rob4t/perl6/ch-2.p6 new file mode 100644 index 0000000000..d705130729 --- /dev/null +++ b/challenge-005/rob4t/perl6/ch-2.p6 @@ -0,0 +1,11 @@ +#!/usr/bin/env perl6 +use v6; + +sub MAIN(Str $file where *.IO.r = '/usr/share/dict/words' ) { + my %a is Bag = $file.IO.lines.map({.words.map({.comb}).flat.Bag}); + + my $max_val = %a.values.max; + for %a.pairs.grep: *.value == $max_val { + say join(": ", .value, .key.kxxv.sort.join); + } +} |
