aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJörg Sommrey <28217714+jo-37@users.noreply.github.com>2024-05-13 17:01:09 +0200
committerJörg Sommrey <28217714+jo-37@users.noreply.github.com>2024-05-17 15:10:31 +0200
commit028dd3b3ee3ce5cd0fa22e00d8d0b3aeceb6590a (patch)
tree6fbe616ddaa45f89f636d0e84ede9218b5300122
parent3feaed4e4c9428d1bfe3a8c501424cc79685e4d5 (diff)
downloadperlweeklychallenge-club-028dd3b3ee3ce5cd0fa22e00d8d0b3aeceb6590a.tar.gz
perlweeklychallenge-club-028dd3b3ee3ce5cd0fa22e00d8d0b3aeceb6590a.tar.bz2
perlweeklychallenge-club-028dd3b3ee3ce5cd0fa22e00d8d0b3aeceb6590a.zip
Solution to task 1
-rwxr-xr-xchallenge-269/jo-37/perl/ch-1.pl58
1 files changed, 58 insertions, 0 deletions
diff --git a/challenge-269/jo-37/perl/ch-1.pl b/challenge-269/jo-37/perl/ch-1.pl
new file mode 100755
index 0000000000..9876b7ee39
--- /dev/null
+++ b/challenge-269/jo-37/perl/ch-1.pl
@@ -0,0 +1,58 @@
+#!/usr/bin/perl -s
+
+use v5.26;
+use Test2::V0;
+
+our ($tests, $examples);
+
+run_tests() if $tests || $examples; # does not return
+
+die <<EOS unless @ARGV;
+usage: $0 [-examples] [-tests] [I...]
+
+-examples
+ run the examples from the challenge
+
+-tests
+ run some tests
+
+I...
+ list of integers
+
+EOS
+
+
+### Input and Output
+
+say +(qw(false true))[mtz(@ARGV)];
+
+
+### Implementation
+#
+# For details see:
+# https://github.sommrey.de/the-bears-den/2024/05/17/ch-269.html#task-1
+
+
+sub mtz {
+ 1 < grep !($_ & 1), @_;
+}
+
+
+### Examples and tests
+
+sub run_tests {
+ SKIP: {
+ skip "examples" unless $examples;
+
+ ok mtz(1, 2, 3, 4, 5), 'example 1';
+ ok mtz(2, 3, 8, 16), 'example 2';
+ ok !mtz(1, 2, 5, 7, 9), 'example 3';
+ }
+
+ SKIP: {
+ skip "tests" unless $tests;
+ }
+
+ done_testing;
+ exit;
+}