diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-04-17 16:50:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-17 16:50:48 +0100 |
| commit | 690b816b7297aa36e6fc8c82533705089e9c4e0a (patch) | |
| tree | c1274a74a529c9965c27fbb37c56ecd3aced1d8a | |
| parent | b7ade3b4aa6074c4023fb46db047be1f1b8a900a (diff) | |
| parent | d1e904c2096dd85535fd5e61f29057ba872f5976 (diff) | |
| download | perlweeklychallenge-club-690b816b7297aa36e6fc8c82533705089e9c4e0a.tar.gz perlweeklychallenge-club-690b816b7297aa36e6fc8c82533705089e9c4e0a.tar.bz2 perlweeklychallenge-club-690b816b7297aa36e6fc8c82533705089e9c4e0a.zip | |
Merge pull request #65 from jmaslak/jmaslak-week4b
Jmaslak week4b
| -rwxr-xr-x | challenge-004/joelle-maslak/perl6/ch-2.p6 | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-004/joelle-maslak/perl6/ch-2.p6 b/challenge-004/joelle-maslak/perl6/ch-2.p6 new file mode 100755 index 0000000000..a8175def20 --- /dev/null +++ b/challenge-004/joelle-maslak/perl6/ch-2.p6 @@ -0,0 +1,38 @@ +#!/usr/bin/env perl6 +use v6; + +# To call this application: +# +# perl6 ch-2.p6 <letters> <filename> +# +# If you want to use /usr/share/dict/words as the word list, you can +# omit the filename. +# +# Example: +# +# perl6 ch-2.p6 aet +# +# which is equivilent to: +# +# perl6 ch-2.p6 eat /usr/share/dict/words +# +# With my Unix dictionary (English), it returns ate, eat, eta, and tea. +# + +sub MAIN(Str:D $letters, Str:D $filename = '/usr/share/dict/words') { + my $matchbag = Bag.new($letters.comb); + my SetHash $dedupe = SetHash.new; # To store matches we gave back + + for $filename.IO.lines -> $word { + my $fcword = $word.fc; + + my $bag = Bag.new($fcword.comb); + + if $bag ~~ $matchbag { + next if $fcword ∈ $dedupe; + $dedupe{$fcword}++; + say $fcword if $bag ~~ $matchbag; + } + } +} + |
