Ethiopian multiplication: Difference between revisions
Content deleted Content added
fortran |
perl |
||
Line 144: | Line 144: | ||
end program EthiopicMult</lang> |
end program EthiopicMult</lang> |
||
=={{header|Perl}}== |
|||
<lang perl>use strict; |
|||
sub halve { return int((shift) / 2); } |
|||
sub double { return (shift) * 2; } |
|||
sub iseven { return ((shift) & 1) == 0; } |
|||
sub ethiopicmult |
|||
{ |
|||
my ($plier, $plicand, $tutor) = @_; |
|||
print "ethiopic multiplication of $plier and $plicand\n" if ($tutor); |
|||
my $r = 0; |
|||
while($plier >= 1) |
|||
{ |
|||
$r += $plicand if (!iseven($plier)); |
|||
if ($tutor) { |
|||
print "$plier, $plicand " . (iseven($plier) ? " struck" : " kept") . "\n"; |
|||
} |
|||
$plier = halve($plier); |
|||
$plicand = double($plicand); |
|||
} |
|||
return $r; |
|||
} |
|||
print ethiopicmult(17,34, 1) . "\n";</lang> |
|||
=={{header|Python}}== |
=={{header|Python}}== |