diff options
| author | Stephen Lynn <bizlsg@localhost.localdomain> | 2023-12-27 08:24:07 +0800 |
|---|---|---|
| committer | Stephen Lynn <bizlsg@localhost.localdomain> | 2023-12-27 08:24:07 +0800 |
| commit | 292ffcd983dd4232331dd60dad3e98eff6a4de7e (patch) | |
| tree | f3e828d07b0728fe8ff89d662422a57226f37f6f | |
| parent | 09ffbd5e40441c537d3550f0040558e5756f9d79 (diff) | |
| download | perlweeklychallenge-club-292ffcd983dd4232331dd60dad3e98eff6a4de7e.tar.gz perlweeklychallenge-club-292ffcd983dd4232331dd60dad3e98eff6a4de7e.tar.bz2 perlweeklychallenge-club-292ffcd983dd4232331dd60dad3e98eff6a4de7e.zip | |
ch-2 improvement
| -rwxr-xr-x | challenge-249/steve-g-lynn/perl/ch-2.pl | 7 |
1 files 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 ...$!"; |
