aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJörg Sommrey <28217714+jo-37@users.noreply.github.com>2020-08-10 23:28:57 +0200
committerJörg Sommrey <28217714+jo-37@users.noreply.github.com>2020-08-12 20:30:24 +0200
commit5f0aefff95cf6f9a410c23cb11124880ea5c61bc (patch)
tree7e86aa28f6899637e09577dd3f07428eaf1560b5
parent06beacb64952894584a87c19363d0b3023654cbd (diff)
downloadperlweeklychallenge-club-5f0aefff95cf6f9a410c23cb11124880ea5c61bc.tar.gz
perlweeklychallenge-club-5f0aefff95cf6f9a410c23cb11124880ea5c61bc.tar.bz2
perlweeklychallenge-club-5f0aefff95cf6f9a410c23cb11124880ea5c61bc.zip
solution for task 2
-rwxr-xr-xchallenge-073/jo-37/perl/ch-2.pl18
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-073/jo-37/perl/ch-2.pl b/challenge-073/jo-37/perl/ch-2.pl
new file mode 100755
index 0000000000..82c9b605c0
--- /dev/null
+++ b/challenge-073/jo-37/perl/ch-2.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+use Test2::V0;
+use List::Util 'min';
+
+sub left_min {
+ # For all array elements:
+ # Take the array slice "left" of the element,
+ # filter for elements smaller than the selected,
+ # take the mininum of those
+ # and set the result to zero if there was nothing to minimize.
+ map {my $e = $_[$_]; min(grep {$_ < $e} @_[0 .. $_-1]) // 0} 0 .. $#_;
+}
+
+is [left_min 7, 8, 3, 12, 10], [0, 7, 0, 3, 3], 'first example';
+is [left_min 4, 6, 5], [0, 4, 4], 'second example';
+
+done_testing;