aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-100/wlmb/perl/ch-1.pl2
-rwxr-xr-xchallenge-100/wlmb/perl/ch-2.pl9
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