diff options
| author | Joelle Maslak <jmaslak@antelope.net> | 2019-04-17 20:40:15 -0600 |
|---|---|---|
| committer | Joelle Maslak <jmaslak@antelope.net> | 2019-04-17 20:40:15 -0600 |
| commit | be88e3c14cb577b26b4bf97d7699f0be9e441404 (patch) | |
| tree | b65af8ded97115f2e941e6092bdde967e7c3868d | |
| parent | fbd4418560776b23aa738fbd0ec8c410a8774693 (diff) | |
| download | perlweeklychallenge-club-be88e3c14cb577b26b4bf97d7699f0be9e441404.tar.gz perlweeklychallenge-club-be88e3c14cb577b26b4bf97d7699f0be9e441404.tar.bz2 perlweeklychallenge-club-be88e3c14cb577b26b4bf97d7699f0be9e441404.zip | |
Also read directions for problem 2 correctly now. :)
| -rwxr-xr-x | challenge-004/joelle-maslak/perl5/ch-2.pl | 16 | ||||
| -rwxr-xr-x | challenge-004/joelle-maslak/perl6/ch-2.p6 | 4 |
2 files changed, 15 insertions, 5 deletions
diff --git a/challenge-004/joelle-maslak/perl5/ch-2.pl b/challenge-004/joelle-maslak/perl5/ch-2.pl index 7d46400f8e..96f5f3280e 100755 --- a/challenge-004/joelle-maslak/perl5/ch-2.pl +++ b/challenge-004/joelle-maslak/perl5/ch-2.pl @@ -26,10 +26,10 @@ if ( @ARGV < 1 or @ARGV > 2 ) { die("Provide letters to use and (optionally # # perl ch-2.pl eat /usr/share/dict/words # -# With my Unix dictionary (English), it returns ate, eat, eta, and tea. +# With my Unix dictionary (English), it returns a, e, t, at, ate, eat, eta, and tea. # -my $match = join '', sort split('', fc($ARGV[0])); # A sotrted string of chars +my $match = fc($ARGV[0]); my %dedupe; my $filename = $ARGV[1] // '/usr/share/dict/words'; @@ -40,10 +40,20 @@ while (my $word = <$fh>) { my $wordmatch = join '', sort split('', $word); - if ($match eq $wordmatch) { + if (partialmatch($match, $wordmatch)) { next if exists $dedupe{$word}; $dedupe{$word} = 1; say $word; } } +sub partialmatch($chars, $word) { + my @chars = sort split '', $chars; + my @word = sort split '', $word; + + for my $c (@chars) { + shift(@word) if ($word[0] // ' ') eq $c; + } + return ! @word; +} + diff --git a/challenge-004/joelle-maslak/perl6/ch-2.p6 b/challenge-004/joelle-maslak/perl6/ch-2.p6 index 6febcd5cfd..c8db36f22b 100755 --- a/challenge-004/joelle-maslak/perl6/ch-2.p6 +++ b/challenge-004/joelle-maslak/perl6/ch-2.p6 @@ -16,7 +16,7 @@ use v6; # # perl6 ch-2.p6 eat /usr/share/dict/words # -# With my Unix dictionary (English), it returns ate, eat, eta, and tea. +# With my Unix dictionary (English), it returns a, e, t, at, ate, eat, eta, and tea. # sub MAIN(Str:D $letters, Str:D $filename = '/usr/share/dict/words') { @@ -28,7 +28,7 @@ sub MAIN(Str:D $letters, Str:D $filename = '/usr/share/dict/words') { my $bag = Bag.new($fcword.comb); - if $bag ~~ $matchbag { + if $bag ⊆ $matchbag { next if $fcword ∈ $dedupe; $dedupe{$fcword}++; say $fcword; |
