From 292ffcd983dd4232331dd60dad3e98eff6a4de7e Mon Sep 17 00:00:00 2001 From: Stephen Lynn Date: Wed, 27 Dec 2023 08:24:07 +0800 Subject: ch-2 improvement --- challenge-249/steve-g-lynn/perl/ch-2.pl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/challenge-249/steve-g-lynn/perl/ch-2.pl b/challenge-249/steve-g-lynn/perl/ch-2.pl index 37d26f55fd..b81273d592 100755 --- a/challenge-249/steve-g-lynn/perl/ch-2.pl +++ b/challenge-249/steve-g-lynn/perl/ch-2.pl @@ -11,12 +11,13 @@ local *DI_string_match = sub { #-- loop through $str indices, # if str[i] is 'D', assign highest in output[i] and decrement it - # if a position i is 'I', assign lowest in output[i] and increment it + # if str[i] is 'I', assign lowest in output[i] and increment it my @retval = (); #-- return value map { - (substr($str,$_,1) eq 'D') && ($retval[$_] = $highest--); - (substr($str,$_,1) eq 'I') && ($retval[$_] = $lowest++); + (substr($str,$_,1) eq 'D') ? + ($retval[$_] = $highest--) : + ($retval[$_] = $lowest++); } 0 .. length($str)-1; ($lowest==$highest) || die "Something wrong ...$!"; -- cgit