diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2020-08-16 13:22:43 +0200 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2020-08-16 13:22:43 +0200 |
| commit | f3bded539cb48537dc014a667b4528bba9c83287 (patch) | |
| tree | 45fa3c6594a1aa1365582bc6aaf3885d269f6cd3 /challenge-073 | |
| parent | 5cfdaee1baa34c2882ffa096864ac271045e9a6e (diff) | |
| download | perlweeklychallenge-club-f3bded539cb48537dc014a667b4528bba9c83287.tar.gz perlweeklychallenge-club-f3bded539cb48537dc014a667b4528bba9c83287.tar.bz2 perlweeklychallenge-club-f3bded539cb48537dc014a667b4528bba9c83287.zip | |
Perl task 1
Diffstat (limited to 'challenge-073')
| -rw-r--r-- | challenge-073/lubos-kolouch/perl/ch-1.pl | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/challenge-073/lubos-kolouch/perl/ch-1.pl b/challenge-073/lubos-kolouch/perl/ch-1.pl new file mode 100644 index 0000000000..d8dbbf3c7b --- /dev/null +++ b/challenge-073/lubos-kolouch/perl/ch-1.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: ch-1.pl +# +# USAGE: ./ch-1.pl +# +# DESCRIPTION: https://perlweeklychallenge.org/blog/perl-weekly-challenge-073/ +# +# Min Sliding Window +# +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: Lubos Kolouch +# ORGANIZATION: +# VERSION: 1.0 +# CREATED: 16.8.2020 12:40 +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use List::Util qw/min/; + +sub compare_versions { + my ($a_ref, $s) = @_; + + my @return_array; + + my $pos = 0; + while (1) { + my $last_index = min(scalar @$a_ref-1, $pos+$s); + + push @return_array, min(@$a_ref[$pos..$last_index]); + last if $last_index == scalar(@$a_ref)-1; + + $pos++; + } + + return \@return_array; +} + + +# TESTS + +use Test::More; + +is_deeply(\compare_versions([1, 5, 0, 2, 9, 3, 7, 6, 4, 8],3),\[0,0,0,2,3,3,4]); +is_deeply(\compare_versions([1, 2, 3],4),\[1]); + +done_testing; |
