From f990fad1624bbc8e7def7ca76703aef0aad3e300 Mon Sep 17 00:00:00 2001 From: E7-87-83 Date: Mon, 21 Jun 2021 07:40:14 +0800 Subject: improve ch-2.pl codes --- challenge-117/cheok-yin-fung/perl/ch-2.pl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/challenge-117/cheok-yin-fung/perl/ch-2.pl b/challenge-117/cheok-yin-fung/perl/ch-2.pl index 40909a2072..a9d6a433f5 100644 --- a/challenge-117/cheok-yin-fung/perl/ch-2.pl +++ b/challenge-117/cheok-yin-fung/perl/ch-2.pl @@ -25,6 +25,7 @@ while (scalar @newarr <= $N) { print "Number of Paths: ", $newarr[-1]; print "\n"; + # * * * * * * * sub ways { my $K = $_[0]; @@ -36,17 +37,17 @@ sub ways { $newstp = [ [ 'L' x $ord ] ]; for my $i (1.. $ord - 1) { push @{$newstp->[$i]}, $stp->[$i-1]->[$_] . 'R' - for (0.. scalar $stp->[$i-1]->@* - 1 ); + for (0.. $stp->[$i-1]->$#*); push @{$newstp->[$i]}, $stp->[$i]->[$_] . 'L' - for (0.. scalar $stp->[$i]->@* - 1 ); + for (0.. $stp->[$i]->$#*); push @{$newstp->[$i]}, $newstp->[$i-1]->[$_] . 'H' - for (0.. scalar $newstp->[$i-1]->@* - 1 ); + for (0.. $newstp->[$i-1]->$#*); } push @{$newstp->[$ord]}, $stp->[$ord-1]->[$_] . 'R' - for (0.. scalar @{$stp->[$ord-1]} - 1 ); + for (0.. $stp->[$ord-1]->$#*); push @{$newstp->[$ord]}, $newstp->[$ord-1]->[$_] . 'H' - for (0.. scalar @{$newstp->[$ord-1]} - 1 ); + for (0.. $newstp->[$ord-1]->$#*); } return $newstp->[-1]; -- cgit