aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJörg Sommrey <28217714+jo-37@users.noreply.github.com>2024-04-22 18:12:18 +0200
committerJörg Sommrey <28217714+jo-37@users.noreply.github.com>2024-04-26 13:00:24 +0200
commitb13afa65925584f7ae3fecad2750faf19f632d5e (patch)
tree6d3b6b42346f692620af20c360fa61b6d7cc2283
parentabdf407fb93a82f09995b16f3656f94df7985543 (diff)
downloadperlweeklychallenge-club-b13afa65925584f7ae3fecad2750faf19f632d5e.tar.gz
perlweeklychallenge-club-b13afa65925584f7ae3fecad2750faf19f632d5e.tar.bz2
perlweeklychallenge-club-b13afa65925584f7ae3fecad2750faf19f632d5e.zip
Solution to task 1
-rwxr-xr-xchallenge-266/jo-37/perl/ch-1.pl68
1 files changed, 68 insertions, 0 deletions
diff --git a/challenge-266/jo-37/perl/ch-1.pl b/challenge-266/jo-37/perl/ch-1.pl
new file mode 100755
index 0000000000..f636db4c2e
--- /dev/null
+++ b/challenge-266/jo-37/perl/ch-1.pl
@@ -0,0 +1,68 @@
+#!/usr/bin/perl -s
+
+
+use v5.24;
+use Test2::V0;
+use List::MoreUtils 'singleton';
+
+our ($tests, $examples);
+
+run_tests() if $tests || $examples; # does not return
+
+die <<EOS unless @ARGV;
+usage: $0 [-examples] [-tests] [SENTENCE...]
+
+-examples
+ run the examples from the challenge
+
+-tests
+ run some tests
+
+SENTENCE
+ a list of sentences
+
+EOS
+
+
+### Input and Output
+
+say "('", join("', '", uncommon_words(@ARGV)), "')";
+
+
+### Implementation
+#
+# For details see:
+# https://github.sommrey.de/the-bears-den/2024/04/26/ch-266.html#task-1
+
+
+sub uncommon_words {
+ singleton map /[[:alpha:]]+/g, @_;
+}
+
+
+### Examples and tests
+
+sub run_tests {
+ SKIP: {
+ skip "examples" unless $examples;
+
+ is [uncommon_words('Mango is sweet', 'Mango is sour')],
+ ['sweet', 'sour'], 'example 1';
+
+ is [uncommon_words('Mango Mango', 'Orange')],
+ ['Orange'], 'example 2';
+
+ is [uncommon_words('Mango is Mango', 'Orange is Orange')],
+ [], 'example 3';
+ }
+
+ SKIP: {
+ skip "tests" unless $tests;
+
+ is [uncommon_words('Twenty-two two-headed beasts headed east.')],
+ [qw(Twenty beasts east)], 'ignore non-alpha';
+ }
+
+ done_testing;
+ exit;
+}