diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-02-16 06:56:18 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-16 06:56:18 +0000 |
| commit | c3cebf3fefa5f4b079c9c4d9969b47b65dbbae53 (patch) | |
| tree | 86db6596b67ea9175243bc004d40004e35258490 | |
| parent | 4c99ef29fe498e19129f64db6243a7308889df6e (diff) | |
| parent | ccc7d762a7b003a169112c1950f72a91a9aefd2e (diff) | |
| download | perlweeklychallenge-club-c3cebf3fefa5f4b079c9c4d9969b47b65dbbae53.tar.gz perlweeklychallenge-club-c3cebf3fefa5f4b079c9c4d9969b47b65dbbae53.tar.bz2 perlweeklychallenge-club-c3cebf3fefa5f4b079c9c4d9969b47b65dbbae53.zip | |
Merge pull request #3538 from wlmb/challenges
Challenges
| -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 |
