diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2020-08-13 10:30:58 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2020-08-13 10:30:58 +0000 |
| commit | 0940ee57dbd2d4a9918a74e52e3cc1266eb5196f (patch) | |
| tree | a280b02c695908561864e2a194d31cc459f8712c /challenge-071/perlboy1967 | |
| parent | 9fe9442bd044a0b85b874c1a19ccee562682992f (diff) | |
| download | perlweeklychallenge-club-0940ee57dbd2d4a9918a74e52e3cc1266eb5196f.tar.gz perlweeklychallenge-club-0940ee57dbd2d4a9918a74e52e3cc1266eb5196f.tar.bz2 perlweeklychallenge-club-0940ee57dbd2d4a9918a74e52e3cc1266eb5196f.zip | |
- Fixed regexp for command-line argument test
- Added second half of 'peak neighbor' test
Diffstat (limited to 'challenge-071/perlboy1967')
| -rwxr-xr-x | challenge-071/perlboy1967/perl/ch-1.pl | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/challenge-071/perlboy1967/perl/ch-1.pl b/challenge-071/perlboy1967/perl/ch-1.pl index eb84290645..c4fb104fd0 100755 --- a/challenge-071/perlboy1967/perl/ch-1.pl +++ b/challenge-071/perlboy1967/perl/ch-1.pl @@ -12,7 +12,7 @@ use warnings; my ($N) = @ARGV; die "Argument must be a positive number ( 1 <= N <= 50)" - unless (defined $N && $N =~ m#^[2-9][0-9]*# and $N <= 50); + unless (defined $N && $N =~ m#^[1-9][0-9]*$# and $N <= 50); my @iPool = (1 .. 50); my @array = map { splice(@iPool, int(rand(scalar(@iPool))), 1) } (1 .. $N); @@ -20,7 +20,8 @@ my @array = map { splice(@iPool, int(rand(scalar(@iPool))), 1) } (1 .. $N); my @peak = map { $array[$_] } grep { $array[$_] - if ($array[$_] > ($array[$_ + 1] // 0)); + if ($array[$_] > ($array[$_ + 1] // 0) and + $array[$_] > ($array[$_ - 1] // 0)); } (0 .. $N - 2); printf "Array: [%s]\n", join(', ', @array); |
