aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
}