aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-090/adam-russell/blog.txt1
-rw-r--r--challenge-090/adam-russell/perl/ch-2.pl10
2 files changed, 8 insertions, 3 deletions
diff --git a/challenge-090/adam-russell/blog.txt b/challenge-090/adam-russell/blog.txt
index e69de29bb2..f29baaf0b9 100644
--- a/challenge-090/adam-russell/blog.txt
+++ b/challenge-090/adam-russell/blog.txt
@@ -0,0 +1 @@
+www.rabbitfarm.com/cgi-bin/blosxom/perl/2020/12/13
diff --git a/challenge-090/adam-russell/perl/ch-2.pl b/challenge-090/adam-russell/perl/ch-2.pl
index 6d5d0a4852..fb6e4c7919 100644
--- a/challenge-090/adam-russell/perl/ch-2.pl
+++ b/challenge-090/adam-russell/perl/ch-2.pl
@@ -8,16 +8,20 @@ use warnings;
sub ethiopian_multiplication{
my($a, $b) = @_;
my @steps;
+ my $product = 0;
my ($x, $y) = ($a, $b);
do{
$x = int($x / 2);
$y = $y * 2;
-print "$x $y\n";
- push @steps, [$x, $y];
+ push @steps, [$x, $y] if $x % 2 != 0;
}until $steps[-1]->[0] == 1 || $steps[-1]->[1] == 1;
+ for my $step (@steps){
+ $product += $step->[1];
+ }
+ return $product;
}
MAIN:{
my($A, $B) = (14, 12);
- ethiopian_multiplication($A, $B);
+ print "$A x $B = " . ethiopian_multiplication($A, $B) . "\n";
}