Created
November 5, 2015 08:58
-
-
Save siasur/61877aff9d143e9ad0ce to your computer and use it in GitHub Desktop.
Die Russische Bauernmultiplikation (auch Ägyptisches Multiplizieren, Abessinische Bauernregel oder Verdopplungs-Halbierungs-Methode genannt) ist ein einfaches Verfahren zur Multiplikation zweier natürlicher Zahlen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function Mul( --[[number]] _x, --[[number]] _y ) | |
local result = 0 | |
while ( _x >= 1 ) do | |
if ( _x%2 ~= 0 ) then | |
result = result + _y | |
end | |
_x = math.floor( _x / 2 ) | |
_y = _y * 2 | |
end | |
return result | |
end | |
print(Mul(47, 42)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment