aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-12-09 02:34:49 +0000
committerGitHub <noreply@github.com>2020-12-09 02:34:49 +0000
commit2c08be3bbf675666dc537f83a78541f44dea8170 (patch)
tree412c043b90c6c3d0f6e95ede0869304f508a3db6
parentf4a0064f131ddf6f2ecc67bbec856d4df9113cf9 (diff)
parente14c1c849dc1988a9c93e08413c86c5105753fcd (diff)
downloadperlweeklychallenge-club-2c08be3bbf675666dc537f83a78541f44dea8170.tar.gz
perlweeklychallenge-club-2c08be3bbf675666dc537f83a78541f44dea8170.tar.bz2
perlweeklychallenge-club-2c08be3bbf675666dc537f83a78541f44dea8170.zip
Merge pull request #2949 from Cris-HD/branch-for-challenge-090
Added challenge 90 solution
-rw-r--r--challenge-090/cristian-heredia/perl/ch-2.pl38
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-090/cristian-heredia/perl/ch-2.pl b/challenge-090/cristian-heredia/perl/ch-2.pl
new file mode 100644
index 0000000000..2aeac8b209
--- /dev/null
+++ b/challenge-090/cristian-heredia/perl/ch-2.pl
@@ -0,0 +1,38 @@
+=begin
+
+ TASK #2 › Ethiopian Multiplication
+ Submitted by: Mohammad S Anwar
+ You are given two positive numbers $A and $B.
+
+ Write a script to demonstrate Ethiopian Multiplication using the given numbers.
+
+=end
+=cut
+
+use strict;
+use warnings;
+
+#variables:
+my $A = 14;
+my $B = 12;
+my $result = 0;
+print "The result for $A * $B is: ";
+calculation();
+
+sub calculation {
+ checkOdd($A);
+ while ($A != 1) {
+ use integer;
+ $A = $A/2;
+ $B = $B*2;
+ checkOdd($A);
+ }
+ print "$result\n";
+}
+
+sub checkOdd {
+ my $number = shift;
+ if ($number%2) {
+ $result = $result + $B;
+ }
+} \ No newline at end of file