aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-04-18 20:23:55 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-04-18 20:23:55 +0100
commitd059f1a16f9ce08854b6ef2c69552802850a4710 (patch)
tree297bf68ae632dc66ea5ebb75931ec90e8c8676fa
parent9448498babb5bd84707759be9ba885bdfa423240 (diff)
downloadperlweeklychallenge-club-d059f1a16f9ce08854b6ef2c69552802850a4710.tar.gz
perlweeklychallenge-club-d059f1a16f9ce08854b6ef2c69552802850a4710.tar.bz2
perlweeklychallenge-club-d059f1a16f9ce08854b6ef2c69552802850a4710.zip
- Tided up Perl solutions to Path Sum.
-rw-r--r--challenge-056/mohammad-anwar/perl/ch-2.pl4
-rw-r--r--challenge-056/mohammad-anwar/perl/ch-2a.pl5
2 files changed, 5 insertions, 4 deletions
diff --git a/challenge-056/mohammad-anwar/perl/ch-2.pl b/challenge-056/mohammad-anwar/perl/ch-2.pl
index a37fba63aa..de8ff6982a 100644
--- a/challenge-056/mohammad-anwar/perl/ch-2.pl
+++ b/challenge-056/mohammad-anwar/perl/ch-2.pl
@@ -24,7 +24,7 @@ my $TREE = {
},
};
-print find_matched_paths($TREE, $SUM), "\n";
+print join("\n", @{find_matched_paths($TREE, $SUM)}), "\n";
sub find_matched_paths {
my ($TREE, $SUM) = @_;
@@ -55,5 +55,5 @@ sub find_matched_paths {
push @$matched_paths, join(" -> ", @$path) if ($total == $SUM);
}
- return join("\n", @$matched_paths);
+ return $matched_paths;
}
diff --git a/challenge-056/mohammad-anwar/perl/ch-2a.pl b/challenge-056/mohammad-anwar/perl/ch-2a.pl
index 091e71361e..7c697a3d08 100644
--- a/challenge-056/mohammad-anwar/perl/ch-2a.pl
+++ b/challenge-056/mohammad-anwar/perl/ch-2a.pl
@@ -4,6 +4,7 @@ use strict;
use warnings;
use Test::More;
+use Test::Deep;
=head1 TREE
@@ -28,7 +29,7 @@ my $unit_tests = {
};
foreach my $sum (keys %$unit_tests) {
- is (find_matched_paths($unit_tests->{$sum}, $sum), "5 -> 4 -> 11 -> 2");
+ is_deeply (find_matched_paths($unit_tests->{$sum}, $sum), ["5 -> 4 -> 11 -> 2"]);
}
done_testing;
@@ -62,5 +63,5 @@ sub find_matched_paths {
push @$matched_paths, join(" -> ", @$path) if ($total == $SUM);
}
- return join("\n", @$matched_paths);
+ return $matched_paths;
}