blob: bb4530dd94198c53ff563715cf66f42d184ad63a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#!/opt/perl/bin/perl
use 5.032;
use strict;
use warnings;
no warnings 'syntax';
use experimental 'signatures';
use experimental 'lexical_subs';
my $TICK = "\N{CHECK MARK}";
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;
}
__END__
|