Anonymous user
Ethiopian multiplication: Difference between revisions
→{{header|UNIX Shell}}: Add more shells.
(Updated D code) |
(→{{header|UNIX Shell}}: Add more shells.) |
||
Line 2,697:
=={{header|UNIX Shell}}==
Tried with ''bash --posix'', and also with Heirloom's ''sh''. Beware that ''bash --posix'' has more features than ''sh''; this script uses only ''sh'' features.
{{works with|Bourne Shell}}
<lang bash>halve()
{
}
double()
{
}
{
}
Line 2,718 ⟶ 2,720:
plicand=$2
r=0
while [ "$plier" -ge 1 ]; do
▲ plier=$(halve $plier)
▲ plicand=$(double $plicand)
done
echo $r
}
# => 578</lang>
While breaking if the --posix flag is passed to bash, the following
{{works with|bash}}
{{works with|pdksh}}
{{works with|zsh}}
<lang bash>halve() {
}
double() {
}
is_even() {
}
Line 2,752 ⟶ 2,754:
local result=0
while
do
is_even
done
echo
}
# => 578</lang>
==={{header|C Shell}}===
<lang csh>alias halve '@ \!:1 /= 2'
alias double '@ \!:1 *= 2'
alias is_even '@ \!:1 = ! ( \!:2 % 2 )'
alias multiply eval \''set multiply_args=( \!*:q ) \\
@ multiply_plier = $multiply_args[2] \\
@ multiply_plicand = $multiply_args[3] \\
@ multiply_result = 0 \\
while ( $multiply_plier > 0 ) \\
is_even multiply_is_even $multiply_plier \\
if ( ! $multiply_is_even ) then \\
@ multiply_result += $multiply_plicand \\
endif \\
halve multiply_plier \\
double multiply_plicand \\
end \\
@ $multiply_args[1] = $multiply_result \\
'\'
multiply p 17 34
echo $p
# => 578</lang>
=={{header|Ursala}}==
|