diff options
| author | Cris-HD <crisn7@hotmail.com> | 2020-12-08 15:22:52 +0100 |
|---|---|---|
| committer | Cris-HD <crisn7@hotmail.com> | 2020-12-08 15:22:52 +0100 |
| commit | e14c1c849dc1988a9c93e08413c86c5105753fcd (patch) | |
| tree | 14b841d6a73bfcf407d6b0c9804efd5229c2b3b5 | |
| parent | 10b020ec45585fac7ef5bca14e0f365ff91bd76d (diff) | |
| download | perlweeklychallenge-club-e14c1c849dc1988a9c93e08413c86c5105753fcd.tar.gz perlweeklychallenge-club-e14c1c849dc1988a9c93e08413c86c5105753fcd.tar.bz2 perlweeklychallenge-club-e14c1c849dc1988a9c93e08413c86c5105753fcd.zip | |
Added challenge 90 solution
| -rw-r--r-- | challenge-090/cristian-heredia/perl/ch-2.pl | 38 |
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 |
