Ethiopian multiplication: Difference between revisions

Content added Content deleted
(→‎{{header|AutoIt}}: added tutor)
Line 157:
Func IsEven($x)
Return (Mod($x,2) == 0)
EndFunc
 
;tutor set to true writes to console
Func Ethiopian($anPlier, $bnPlicand, $fTutorbTutor = True)
If $fTutorbTutor Then _
ConsoleWrite(StringFormat("Ethiopian multiplication of %d by %d...\n", $anPlier, $bnPlicand))
Local $r = 0
WhileLocal ($anResult >= 1)0
While ($nPlier >= 1)
If Not IsEven($anPlier) Then
If $fTutorbTutor Then ConsoleWrite(StringFormat("%d\t%d\tStriketKeep\n", $anPlier, $bnPlicand))
$nResult += $nPlicand
Else
If $fTutorbTutor Then ConsoleWrite(StringFormat("%d\t%d\tKeeptStrike\n", $anPlier, $bnPlicand))
$r += $b
EndIf
$anPlier = Halve($anPlier)
$bnPlicand = Double($bnPlicand)
WEnd
If $fTutorbTutor Then ConsoleWrite(StringFormat("Answer = %d\n", $rnResult) &@LF)
Return $rnResult
EndFunc
 
MsgBox(0, "Ethiopian multiplication of 17 by 34", Ethiopian(17, 34) )
;tutor set to true writes to console
Ethiopian(17, 34, True)
</lang>