aboutsummaryrefslogtreecommitdiff
path: root/challenge-075/mohammad-anwar
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-12-10 12:40:36 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-12-10 12:40:36 +0000
commit69ce9c30f8de5b734e51bdd00bb87eedece179fd (patch)
tree083a25c6005bae891e3381fc7fac07d5d46d9b0a /challenge-075/mohammad-anwar
parenta4c5efa0df2d132a3bdb1be3dcbc541d160ec0a7 (diff)
downloadperlweeklychallenge-club-69ce9c30f8de5b734e51bdd00bb87eedece179fd.tar.gz
perlweeklychallenge-club-69ce9c30f8de5b734e51bdd00bb87eedece179fd.tar.bz2
perlweeklychallenge-club-69ce9c30f8de5b734e51bdd00bb87eedece179fd.zip
- Tidied up Perl solution to task 1 of week 75.
Diffstat (limited to 'challenge-075/mohammad-anwar')
-rwxr-xr-xchallenge-075/mohammad-anwar/perl/ch-1.pl18
1 files changed, 17 insertions, 1 deletions
diff --git a/challenge-075/mohammad-anwar/perl/ch-1.pl b/challenge-075/mohammad-anwar/perl/ch-1.pl
index 7749fa9364..083a22b4e7 100755
--- a/challenge-075/mohammad-anwar/perl/ch-1.pl
+++ b/challenge-075/mohammad-anwar/perl/ch-1.pl
@@ -11,6 +11,7 @@
use strict;
use warnings;
+my $DEBUG = 0;
my $COINS = $ARGV[0] || "1, 2, 4";
my $SUM = $ARGV[1] || 6;
@@ -30,7 +31,7 @@ sub coins_sum {
my $matrix;
# Sum of 0 can be achieved in one possible way.
- $matrix->[$_][0] = 1 for (0 .. $size+1);
+ $matrix->[$_][0] = 1 for (0 .. $size);
foreach my $i (0 .. $size) {
@@ -51,9 +52,24 @@ sub coins_sum {
}
}
+ show_matrix($matrix) if $DEBUG;
return $matrix->[$size][$sum];
}
+sub show_matrix {
+ my ($matrix) = @_;
+
+ my $rows = @$matrix;
+ my $cols = @{$matrix->[0]};
+
+ foreach my $r (0 .. $rows-1) {
+ foreach my $c (0 .. $cols-1) {
+ print sprintf("%s ", $matrix->[$r][$c]);
+ }
+ print "\n";
+ }
+}
+
sub prepare {
my ($coins) = @_;