From 9091fef736477a14d7f8092e1355bd49d52beac0 Mon Sep 17 00:00:00 2001 From: Fung Cheok Yin <61836418+E7-87-83@users.noreply.github.com> Date: Tue, 28 Apr 2020 13:56:05 +0800 Subject: Update ch-2.pl --- challenge-058/cheok-yin-fung/perl/ch-2.pl | 7 +++++-- 1 file 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; -- cgit