aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFung Cheok Yin <61836418+E7-87-83@users.noreply.github.com>2020-08-03 07:51:23 +0800
committerGitHub <noreply@github.com>2020-08-03 07:51:23 +0800
commitad050d5b762c999921e171c228476adc05b0bde5 (patch)
tree2865d73b3e12aab049e04ad28ac0d4c7a84efb18
parentb98474b85141162f406fae9765e873634008f913 (diff)
downloadperlweeklychallenge-club-ad050d5b762c999921e171c228476adc05b0bde5.tar.gz
perlweeklychallenge-club-ad050d5b762c999921e171c228476adc05b0bde5.tar.bz2
perlweeklychallenge-club-ad050d5b762c999921e171c228476adc05b0bde5.zip
Update ch-1.pl
-rw-r--r--challenge-071/cheok-yin-fung/perl/ch-1.pl9
1 files changed, 7 insertions, 2 deletions
diff --git a/challenge-071/cheok-yin-fung/perl/ch-1.pl b/challenge-071/cheok-yin-fung/perl/ch-1.pl
index a395d02ddc..996474cd7a 100644
--- a/challenge-071/cheok-yin-fung/perl/ch-1.pl
+++ b/challenge-071/cheok-yin-fung/perl/ch-1.pl
@@ -13,8 +13,13 @@ my @peak_eles = ();
if ($ARGV[0]) {$N = $ARGV[0];} else {$N = 10;}
-for (1..$N) {
- push @seq, 1+int(rand(50))
+while ($#seq < $N) {
+ my $a = 1+int(rand(50));
+ 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 {