aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-08-13 01:57:24 +0100
committerGitHub <noreply@github.com>2020-08-13 01:57:24 +0100
commit9fe9442bd044a0b85b874c1a19ccee562682992f (patch)
treea8d99bd5709645b1938ad0acc9b72ca24d62bd6f
parent8c2b53a3e2c90ce742db15c101fc3f732c7ec2c2 (diff)
parent8b17684ca61703acd0af53c02f736fb1448545b1 (diff)
downloadperlweeklychallenge-club-9fe9442bd044a0b85b874c1a19ccee562682992f.tar.gz
perlweeklychallenge-club-9fe9442bd044a0b85b874c1a19ccee562682992f.tar.bz2
perlweeklychallenge-club-9fe9442bd044a0b85b874c1a19ccee562682992f.zip
Merge pull request #2071 from E7-87-83/master
Fix PWC#071 ch-1.pl
-rw-r--r--challenge-071/cheok-yin-fung/perl/ch-1.pl17
1 files changed, 12 insertions, 5 deletions
diff --git a/challenge-071/cheok-yin-fung/perl/ch-1.pl b/challenge-071/cheok-yin-fung/perl/ch-1.pl
index 996474cd7a..15a144b485 100644
--- a/challenge-071/cheok-yin-fung/perl/ch-1.pl
+++ b/challenge-071/cheok-yin-fung/perl/ch-1.pl
@@ -10,29 +10,36 @@ use warnings;
my $N;
my @seq = ();
my @peak_eles = ();
+my %unique = (); #edited on 13th Aug
if ($ARGV[0]) {$N = $ARGV[0];} else {$N = 10;}
-while ($#seq < $N) {
+
+
+while ($#seq < $N-1) { #edited on 13th Aug
my $a = 1+int(rand(50));
- push @seq, $a unless exists $unique{$a} ;
+ push @seq, $a unless exists $unique{$a} ;
$unique{ $a } = 1;
# notes on 10min before deadline: I forgot to implement the uniqueness
# requirement until I saw laurent_r's blog.
# Therefore, The code of generating the close to his.
}
-sub checkpeak {
+sub checkpeak_inside {
my $p = $_[0];
if ($seq[$p-1] < $seq[$p] and $seq[$p+1] < $seq[$p]) {
push @peak_eles, $seq[$p];
}
}
-for (1..$N-2) {
- checkpeak($_);
+if ($seq[0]>$seq[1]) {push @peak_eles, $seq[0];} #edited on 13th Aug
+
+for (1..$#seq-1) {
+ checkpeak_inside($_);
}
+if ($seq[-1]>$seq[-2]) {push @peak_eles, $seq[-1];} #edited on 13th Aug
+
print "Array: [ ", join ", ", @seq;
print "]\n";
print "Peak: [ ", join ", ", @peak_eles;