aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-02-17 04:47:22 +0000
committerdrbaggy <js5@sanger.ac.uk>2021-02-17 04:47:22 +0000
commitab47baa901ee68bafd45af9d4154afda189d180a (patch)
treee738ec95cd0bcd773b61d64c2d17936bc5397367
parent6c4319b9b87a87ea03c7d4dc75fbf7b7f4c84797 (diff)
downloadperlweeklychallenge-club-ab47baa901ee68bafd45af9d4154afda189d180a.tar.gz
perlweeklychallenge-club-ab47baa901ee68bafd45af9d4154afda189d180a.tar.bz2
perlweeklychallenge-club-ab47baa901ee68bafd45af9d4154afda189d180a.zip
tidy up code so isn't wider than 72 characters
-rw-r--r--challenge-100/james-smith/perl/ch-2.pl18
1 files changed, 11 insertions, 7 deletions
diff --git a/challenge-100/james-smith/perl/ch-2.pl b/challenge-100/james-smith/perl/ch-2.pl
index a2f18d481e..10dc496412 100644
--- a/challenge-100/james-smith/perl/ch-2.pl
+++ b/challenge-100/james-smith/perl/ch-2.pl
@@ -62,17 +62,21 @@ sub triangle_sum_1point5_liner {
## A subroutine to display the triangle indicating the route!
sub display_sum {
- my @tri = map{ [@{$_}] } @_; ## Deep copy the triangle as the search is destructive
- my @route; ## For each node in the "current" bottom row, the route is the list
- ## of indecies of the child nodes that make up the "optimal" path
- ## use implicit my on $b....
+ my @tri = map{ [@{$_}] } @_; ## Deep copy the triangle as the
+ ## search is destructive
+ my @route; ## For each node in the "current" bottom row, the route
+ ## is the list of indecies of the child nodes that make
+ ## up the "optimal" path
+ ## We use the implicit my on $b
while(@{$b = pop @tri}>1) {
($tri[-1][$_],$route[$_]) = $b->[$_]<$b->[$_+1]
? ( $tri[-1][$_] + $b->[$_], [$_, @{$route[$_ ]||[]}] )
- : ( $tri[-1][$_] + $b->[$_+1], [$_+1,@{$route[$_+1]||[]}] ) foreach 0..@tri-1;
+ : ( $tri[-1][$_] + $b->[$_+1], [$_+1,@{$route[$_+1]||[]}] )
+ foreach 0..@tri-1;
}
- @route = (0,@{$route[0]}); ## We need to add the top node index (always 0)
- ## At the same time we can just take the first (only)
+ @route = (0,@{$route[0]}); ## We need to add the top node index
+ ## (always 0), at the same time we can
+ ## just take the first (only)
## path out of the 2d route matrix;
print ## Assume all cell numbers are single digits...
'',