diff options
| author | Fung Cheok Yin <61836418+E7-87-83@users.noreply.github.com> | 2020-04-28 13:56:05 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-28 13:56:05 +0800 |
| commit | 9091fef736477a14d7f8092e1355bd49d52beac0 (patch) | |
| tree | 97420b68140dddb02c9e067311d7a4bad5a81a53 | |
| parent | a26ffe4606ca77c66eda7c81c7e2d9f4bb611c8c (diff) | |
| download | perlweeklychallenge-club-9091fef736477a14d7f8092e1355bd49d52beac0.tar.gz perlweeklychallenge-club-9091fef736477a14d7f8092e1355bd49d52beac0.tar.bz2 perlweeklychallenge-club-9091fef736477a14d7f8092e1355bd49d52beac0.zip | |
Update ch-2.pl
| -rw-r--r-- | challenge-058/cheok-yin-fung/perl/ch-2.pl | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/challenge-058/cheok-yin-fung/perl/ch-2.pl b/challenge-058/cheok-yin-fung/perl/ch-2.pl index 3be4ef6dfb..443054141a 100644 --- a/challenge-058/cheok-yin-fung/perl/ch-2.pl +++ b/challenge-058/cheok-yin-fung/perl/ch-2.pl @@ -23,7 +23,6 @@ my @H = (27, 21, 37, 4, 19, 52, 23, 64, 1, 7, 51, 17, 24, 50, 3, 2, # end: from the question statement
my $N = $#H+1;
-my @inversion_seq;
my %height_appeartime;
for (1..$N) { $height_appeartime{$_} = $H[$_-1]; }
@@ -43,7 +42,11 @@ for my $i (0..$N-1) { for (0..$N-1) {
push @possible_place, $_ if $placement[$_] == -1;
}
- $placement[ $possible_place[ $inversion_seq[$i] ] ] = $i;
+ if ( defined($possible_place[$inversion_seq[$i]]) ) {
+ $pos = $possible_place[ $inversion_seq[$i] ];
+ } else {die "ERROR";}
+
+ $placement[ $pos ] = $i;
}
@placement = map { $_+1 } @placement;
|
