diff options
| author | Luis Mochan <mochan@fis.unam.mx> | 2021-02-15 17:26:00 -0600 |
|---|---|---|
| committer | Luis Mochan <mochan@fis.unam.mx> | 2021-02-15 17:26:00 -0600 |
| commit | 8425624928e6067d82d4d0f54c003bcc690b03c8 (patch) | |
| tree | 6e5ca06b7eb51bbd4bdb66b7bd9dae35f8db67e3 | |
| parent | 59ba9ac359ee6fe8fba25487ffe4b665cae57ff5 (diff) | |
| download | perlweeklychallenge-club-8425624928e6067d82d4d0f54c003bcc690b03c8.tar.gz perlweeklychallenge-club-8425624928e6067d82d4d0f54c003bcc690b03c8.tar.bz2 perlweeklychallenge-club-8425624928e6067d82d4d0f54c003bcc690b03c8.zip | |
Simplify the codes slightly
| -rwxr-xr-x | challenge-100/wlmb/perl/ch-1.pl | 2 | ||||
| -rwxr-xr-x | challenge-100/wlmb/perl/ch-2.pl | 9 |
2 files changed, 5 insertions, 6 deletions
diff --git a/challenge-100/wlmb/perl/ch-1.pl b/challenge-100/wlmb/perl/ch-1.pl index 6cc0f7ef7b..31284205c7 100755 --- a/challenge-100/wlmb/perl/ch-1.pl +++ b/challenge-100/wlmb/perl/ch-1.pl @@ -13,7 +13,7 @@ sub usage { Converts time between 12 and 24 hour formats Usage; ./ch-1.pl time1 time2 ... - Each argument must have the format hh:mm:ss ampm + Each argument must have the format "hh:mm:ss ampm" where the minutes and seconds are optional and ampm is either am or pm or null. If ampm is given, the hour should be not greater than 12 nor diff --git a/challenge-100/wlmb/perl/ch-2.pl b/challenge-100/wlmb/perl/ch-2.pl index 5716c3e031..eb9e60713e 100755 --- a/challenge-100/wlmb/perl/ch-2.pl +++ b/challenge-100/wlmb/perl/ch-2.pl @@ -25,13 +25,12 @@ my @next_row=(0)x@{$rows[-1]}; my $cost; my @choices; foreach my $current_row(reverse @rows){ # move upwards - my @current_row=pairwise {$a+$b} @$current_row, @next_row; # + my @current_row=pairwise {$a+$b} @$current_row, @next_row; #get totalcost for each element $cost=$current_row[0],last if @current_row==1; # done? # Find best choices for each index of the row above - @next_row=map {min ($current_row[$_], $current_row[$_+1])} (0..@current_row-2); - # and register their indices - my @chosen_indices=map {$next_row[$_]==$current_row[$_]?$_:$_+1} (0..@current_row-2); - # Build a triangle of chosen indices + my @chosen_indices=map {$current_row[$_]<=$current_row[$_+1]?$_:$_+1}(0..@current_row-2); + @next_row=@current_row[@chosen_indices]; + # Build a triangle of chosen indices for later display unshift @choices, [@chosen_indices]; } #print input triangle and optimal cost |
