diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2020-08-16 13:38:30 +0200 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2020-08-16 13:38:30 +0200 |
| commit | d8c83072f436c41f64d2a0c4da6fed0b1a986251 (patch) | |
| tree | 3b14057594a61e8666e04da108c9d08eb6aca096 | |
| parent | f3bded539cb48537dc014a667b4528bba9c83287 (diff) | |
| download | perlweeklychallenge-club-d8c83072f436c41f64d2a0c4da6fed0b1a986251.tar.gz perlweeklychallenge-club-d8c83072f436c41f64d2a0c4da6fed0b1a986251.tar.bz2 perlweeklychallenge-club-d8c83072f436c41f64d2a0c4da6fed0b1a986251.zip | |
Challenge 2 Perl LK
| -rw-r--r-- | challenge-073/lubos-kolouch/perl/ch-2.pl | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/challenge-073/lubos-kolouch/perl/ch-2.pl b/challenge-073/lubos-kolouch/perl/ch-2.pl new file mode 100644 index 0000000000..c1638b658c --- /dev/null +++ b/challenge-073/lubos-kolouch/perl/ch-2.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: ch-2.pl +# +# USAGE: ./ch-2.pl +# +# DESCRIPTION: https://perlweeklychallenge.org/blog/perl-weekly-challenge-073/ +# +# Smallest Neighbour +# +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: Lubos Kolouch +# ORGANIZATION: +# VERSION: 1.0 +# CREATED: 16.8.2020 13:40 +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; + +sub get_smallest { + my $a_ref = shift; + + my @return_array = 0; + my $min = @$a_ref[0]; + + for my $i (1 .. scalar @$a_ref-1) { + + if ($min < $a_ref->[$i]) { + push @return_array, $min; + } else { + push @return_array, 0; + } + + $min = $a_ref->[$i] if @$a_ref[$i] < $min; + + } + + return \@return_array; +} + +# TESTS + +use Test::More; + +is_deeply(\get_smallest([7, 8, 3, 12, 10]),\[0, 7, 0, 3, 3]); +is_deeply(\get_smallest([4, 6, 5]),\[0, 4, 4]); + +done_testing; |
