aboutsummaryrefslogtreecommitdiff
path: root/challenge-262
diff options
context:
space:
mode:
authorJörg Sommrey <28217714+jo-37@users.noreply.github.com>2024-03-25 17:12:27 +0100
committerJörg Sommrey <28217714+jo-37@users.noreply.github.com>2024-03-28 09:56:13 +0100
commit8fd1e1114b3c8f2307194d9edb2d52d9c76a833b (patch)
tree966e334b617b6730825d737caa524279aae32c0b /challenge-262
parent449ecffc882396ce47e3e2911ce7aeb690538f93 (diff)
downloadperlweeklychallenge-club-8fd1e1114b3c8f2307194d9edb2d52d9c76a833b.tar.gz
perlweeklychallenge-club-8fd1e1114b3c8f2307194d9edb2d52d9c76a833b.tar.bz2
perlweeklychallenge-club-8fd1e1114b3c8f2307194d9edb2d52d9c76a833b.zip
Solution to task 1
Diffstat (limited to 'challenge-262')
-rwxr-xr-xchallenge-262/jo-37/perl/ch-1.pl55
1 files changed, 55 insertions, 0 deletions
diff --git a/challenge-262/jo-37/perl/ch-1.pl b/challenge-262/jo-37/perl/ch-1.pl
new file mode 100755
index 0000000000..bff884ad9f
--- /dev/null
+++ b/challenge-262/jo-37/perl/ch-1.pl
@@ -0,0 +1,55 @@
+#!/usr/bin/perl -s
+
+use v5.24;
+use Test2::V0;
+use List::Util qw(max reduce);
+
+our ($tests, $examples);
+
+run_tests() if $tests || $examples; # does not return
+
+die <<EOS unless @ARGV;
+usage: $0 [-examples] [-tests] [--] [N...]
+
+-examples
+ run the examples from the challenge
+
+-tests
+ run some tests
+
+N...
+ list of numbers
+
+EOS
+
+
+### Input and Output
+
+say mpn(@ARGV);
+
+
+### Implementation
+
+sub mpn {
+ max +(reduce {$a->[1 + ($b <=> 0)]++; $a} [0,0,0], @_)->@[0,2];
+}
+
+
+### Examples and tests
+
+sub run_tests {
+ SKIP: {
+ skip "examples" unless $examples;
+
+ is mpn(-3, 1, 2, -1, 3, -2, 4), 4, 'example 1';
+ is mpn(-1, -2, -3, 1), 3, 'example 2';
+ is mpn(1,2), 2, 'example 3';
+ }
+
+ SKIP: {
+ skip "tests" unless $tests;
+ }
+
+ done_testing;
+ exit;
+}