Ethiopian multiplication: Difference between revisions

→‎{{header|Bash}}: Removed as there is a bash version under Unix/Shell
m (→‎{{header|Bash}}: stupid typo)
(→‎{{header|Bash}}: Removed as there is a bash version under Unix/Shell)
Line 254:
print ethiopian(17, 34)
}</lang>
 
=={{header|Bash}}==
 
<lang bash>halve() {
local n=$1
echo -n $(( n >> 1 ))
}
 
double() {
local n=$1
echo -n $(( n << 1 ))
}
 
is_even() {
local n=$1
[ $(( n & 1 )) -eq 0 ]
}
 
multiply() {
local plier=$1
local plicand=$2
local result=0
 
while [ $plier -gt 0 ]
do
! is_even $plier && (( result += plicand ))
plier=$( halve $plier )
plicand=$( double $plicand )
done
echo -n $result
}
 
echo $( multiply 17 34 )</lang>
 
=={{header|BASIC}}==
Anonymous user