aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2020-12-14 00:03:46 +0100
committerAbigail <abigail@abigail.be>2020-12-14 00:03:46 +0100
commitb3fc767b2ae0a07ff45f6f0a754fd2bf7d27bd5b (patch)
treef797795f996ae47410b0c8c4c8e8e5a6c0a2b8f2
parent725d0808838758b9a450edf5001eb5caad4460a0 (diff)
downloadperlweeklychallenge-club-b3fc767b2ae0a07ff45f6f0a754fd2bf7d27bd5b.tar.gz
perlweeklychallenge-club-b3fc767b2ae0a07ff45f6f0a754fd2bf7d27bd5b.tar.bz2
perlweeklychallenge-club-b3fc767b2ae0a07ff45f6f0a754fd2bf7d27bd5b.zip
Comments
-rw-r--r--challenge-090/abigail/perl/ch-2.pl12
1 files changed, 12 insertions, 0 deletions
diff --git a/challenge-090/abigail/perl/ch-2.pl b/challenge-090/abigail/perl/ch-2.pl
index 68a45d0c7d..bb4530dd94 100644
--- a/challenge-090/abigail/perl/ch-2.pl
+++ b/challenge-090/abigail/perl/ch-2.pl
@@ -16,13 +16,25 @@ binmode STDOUT, ":utf8";
while (<>) {
use integer;
my ($A, $B) = /([0-9]+) \s+ ([0-9]+)/x or next;
+ #
+ # Max width of the left and right columns.
+ #
my $w1 = length $A;
my $w2 = length (my $product = $A * $B);
while ($A) {
+ #
+ # Print a line, add a tick mark if the left column is odd
+ #
printf "%${w1}d %${w2}d %s\n" => $A, $B, $A % 2 ? $TICK : "";
+ #
+ # Divide and double
+ #
$A /= 2;
$B *= 2;
}
+ #
+ # Print the sum
+ #
say " " x $w1, " ", "-" x $w2, " +";
say " " x $w1, " ", $product;
}