diff options
| author | Abigail <abigail@abigail.be> | 2021-02-12 02:36:58 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-03-04 18:57:25 +0100 |
| commit | 302e409fc2c09c271c25c84ff0b3042b55729c07 (patch) | |
| tree | 11cefd9d3a4ebe4e6c0cd9187b1281ef126f35b9 /challenge-004 | |
| parent | 2237d53c685470f88deff3612da8b0fa825b1451 (diff) | |
| download | perlweeklychallenge-club-302e409fc2c09c271c25c84ff0b3042b55729c07.tar.gz perlweeklychallenge-club-302e409fc2c09c271c25c84ff0b3042b55729c07.tar.bz2 perlweeklychallenge-club-302e409fc2c09c271c25c84ff0b3042b55729c07.zip | |
Test cases for week 4, part 2
Diffstat (limited to 'challenge-004')
| -rw-r--r-- | challenge-004/abigail/perl/ch-2.pl | 59 | ||||
| -rw-r--r-- | challenge-004/abigail/t/ctest.ini | 9 | ||||
| -rw-r--r-- | challenge-004/abigail/t/input-2-1 | 2 | ||||
| -rw-r--r-- | challenge-004/abigail/t/input-2-2 | 1 | ||||
| -rw-r--r-- | challenge-004/abigail/t/output-2-1.exp | 5 | ||||
| -rw-r--r-- | challenge-004/abigail/t/output-2-2.exp | 262 | ||||
| -rw-r--r-- | challenge-004/abigail/t/words.txt | 45 |
7 files changed, 366 insertions, 17 deletions
diff --git a/challenge-004/abigail/perl/ch-2.pl b/challenge-004/abigail/perl/ch-2.pl index 7d252aa886..20cd5148b0 100644 --- a/challenge-004/abigail/perl/ch-2.pl +++ b/challenge-004/abigail/perl/ch-2.pl @@ -1,26 +1,51 @@ -use 5.026; +#!/opt/perl/bin/perl + +use 5.032; use strict; use warnings; no warnings 'syntax'; +use experimental 'signatures'; +use experimental 'lexical_subs'; + # -# Assume the list of letters are the arguments. Read the list -# of words from STDIN +# See ../README.md +# + +# +# Run as: perl ch-2.pl -f FILE < input-file +# + # -my %letters; -$letters {$_} ++ for "@ARGV" =~ /[a-z]/g; - -WORD: while (<STDIN>) { - chomp; - next if /[^a-z]/; - my %l; - $l {$_} ++ for split //; - foreach my $c (keys %l) { - no warnings 'uninitialized'; - next WORD if $letters {$c} < $l {$c}; - } - say; +# The -f FILE determines the file to read words from. +# The input file contains sets of letters, one set per line. +# + +use Getopt::Long; +GetOptions 'f=s' => \my $file, +; + +die "Usage: $0 -f FILE" unless defined $file; + +sub find_words ($file, $letters) { + return if $letters =~ /[^a-z]/i; + open my $fh, "<", $file or die "open $file: $!"; + while (my $word = <$fh>) { + chomp $word; + # + # Remove each letter from (a copy of) $word. + # If we end up with an empty string, we can + # from $word from the letters of $letters. + # + my $copy = $word; + $copy =~ s/\Q$_//i for split // => $letters; + length ($copy) or say $word; + } } -__END__ + +while (my $letters = <>) { + chomp $letters; + find_words $file => $letters; +} diff --git a/challenge-004/abigail/t/ctest.ini b/challenge-004/abigail/t/ctest.ini index 0383d4c587..558a282cc3 100644 --- a/challenge-004/abigail/t/ctest.ini +++ b/challenge-004/abigail/t/ctest.ini @@ -1,5 +1,14 @@ [names]
1-1 = Pi, 3242 digits
+2-1 = Small wordlist
[challenges/1]
extra_tests = Check_Program_Size
+
+
+[2-1]
+args = -f t/words.txt
+
+
+[2-2]
+args = -f /usr/share/dict/words
diff --git a/challenge-004/abigail/t/input-2-1 b/challenge-004/abigail/t/input-2-1 new file mode 100644 index 0000000000..f0a1800316 --- /dev/null +++ b/challenge-004/abigail/t/input-2-1 @@ -0,0 +1,2 @@ +letterbomb +words diff --git a/challenge-004/abigail/t/input-2-2 b/challenge-004/abigail/t/input-2-2 new file mode 100644 index 0000000000..fb4fc0bd4c --- /dev/null +++ b/challenge-004/abigail/t/input-2-2 @@ -0,0 +1 @@ +letterbomb diff --git a/challenge-004/abigail/t/output-2-1.exp b/challenge-004/abigail/t/output-2-1.exp new file mode 100644 index 0000000000..bff1e61ba0 --- /dev/null +++ b/challenge-004/abigail/t/output-2-1.exp @@ -0,0 +1,5 @@ +be +letter +to +word +words diff --git a/challenge-004/abigail/t/output-2-2.exp b/challenge-004/abigail/t/output-2-2.exp new file mode 100644 index 0000000000..c7906a792d --- /dev/null +++ b/challenge-004/abigail/t/output-2-2.exp @@ -0,0 +1,262 @@ +B +b +be +Bee +bee +beer +beet +Bel +bel +belt +belter +bemole +bemolt +ber +bere +beret +berm +Beroe +Bert +bet +betel +better +bettor +bleb +blee +bleo +blet +blo +blob +blore +blot +blotter +bo +Bob +bob +Boer +bole +bolete +bolt +bolter +bom +bomb +bomber +bor +bore +boree +borele +bort +bot +bote +bott +bottle +bottler +bree +breme +Bret +bret +Brett +brett +brob +brome +brot +E +e +ebb +Eboe +eboe +eel +eelbob +eer +el +elb +Elbert +elm +Elmer +elt +Em +em +ember +embole +embottle +eme +emote +er +ere +ettle +L +l +Lee +lee +leer +leet +Leo +Ler +lerot +let +lete +Leto +Lett +letter +Lo +lo +lob +lobber +lobe +lore +Lot +lot +lote +Lotte +lotter +M +m +me +meet +mel +mele +meloe +melt +melter +Meo +Mer +mere +merel +merl +merle +mero +met +mete +metel +meteor +meter +Metol +mettle +Mo +mo +mob +mobber +moble +Moe +Mole +mole +moler +molt +molter +mor +more +morel +mort +mot +mote +motel +moter +motet +Mott +mott +motte +mottle +mottler +Mr +O +o +obe +oe +oer +Ole +olm +om +omber +ombrette +omelet +omer +or +orb +orblet +ore +orle +orlet +ort +ortet +otter +R +r +re +reb +rebel +reblot +rebob +rebolt +rebottle +Ree +ree +reel +reem +reet +rel +relet +relot +remble +remelt +remote +ret +retem +retomb +Ro +Rob +rob +robe +roble +roe +role +Rome +rot +rote +rottle +T +t +te +tebbet +Tebet +tee +teel +teem +teer +teet +tele +telome +telt +tembe +temblor +term +tete +tetel +tetrole +to +tobe +toe +tol +tole +tolt +tolter +Tom +tomb +tombe +tomblet +tome +tomelet +Tor +tor +tore +tort +tot +tote +totem +toter +treble +tree +tremble +tremetol +tret +trombe +trot diff --git a/challenge-004/abigail/t/words.txt b/challenge-004/abigail/t/words.txt new file mode 100644 index 0000000000..118a706bd1 --- /dev/null +++ b/challenge-004/abigail/t/words.txt @@ -0,0 +1,45 @@ +Disclaimer +Print +Proctor +Scimon +The +You +a +all +and +are +be +by +can +case +challenge +containing +duplicates +each +file +from +given +have +insensitive +letter +letters +line +list +made +of +once +only +per +proposed +that +the +them +there +though +to +use +using +was +word +words +you |
