diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2020-08-10 23:28:41 +0200 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2020-08-12 20:30:05 +0200 |
| commit | 06beacb64952894584a87c19363d0b3023654cbd (patch) | |
| tree | 7e881c4af48945d4509bf7151b4923affab52bae | |
| parent | bd9eb24a17a7ed68df7e390960424e86c6a5b55d (diff) | |
| download | perlweeklychallenge-club-06beacb64952894584a87c19363d0b3023654cbd.tar.gz perlweeklychallenge-club-06beacb64952894584a87c19363d0b3023654cbd.tar.bz2 perlweeklychallenge-club-06beacb64952894584a87c19363d0b3023654cbd.zip | |
solution for task 1
| -rwxr-xr-x | challenge-073/jo-37/perl/ch-1.pl | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-073/jo-37/perl/ch-1.pl b/challenge-073/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..67372bc6b5 --- /dev/null +++ b/challenge-073/jo-37/perl/ch-1.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl + +use Test2::V0; +use List::Util 'min'; + +# first arg: window size +# remaining args: input array +sub sliding_min { + my $S = shift; + + # Take the minimum of a sliding window + map min(@_[$_ .. $_ + $S - 1]), 0 .. $#_ - $S + 1; +} + +is [sliding_min 3, (1, 5, 0, 2, 9, 3, 7, 6, 4, 8)], + [0, 0, 0, 2, 3, 3, 4, 4], 'example from challenge'; + +done_testing; |
