Ethiopian multiplication: Difference between revisions
Content added Content deleted
(Undo revision 79599 by 64.164.130.3 No attempt to use functions to halve, double, or test for evenness.) |
No edit summary |
||
Line 145: | Line 145: | ||
578 |
578 |
||
</pre> |
</pre> |
||
=={{header|AutoIt}}== |
|||
<lang AutoIt> |
|||
Func Halve($x) |
|||
Return Int($x/2) |
|||
EndFunc |
|||
Func Double($x) |
|||
Return ($x*2) |
|||
EndFunc |
|||
Func IsEven($x) |
|||
Return Mod($x,2) == 0 |
|||
EndFunc |
|||
Func Ethiopian($a, $b) |
|||
Local $r = 0 |
|||
while ($a >= 1) |
|||
If Not IsEven($a) Then |
|||
$r += $b |
|||
EndIf |
|||
$a = Halve($a) |
|||
$b = Double($b) |
|||
WEnd |
|||
Return $r |
|||
EndFunc |
|||
MsgBox(0, 'Ethiopian Example', Ethiopian(17, 34) ) |
|||
</lang> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |