Created
March 21, 2015 18:45
-
-
Save EHDEV/41493f7423758003b4c9 to your computer and use it in GitHub Desktop.
Ancient Ethiopian Multiplication by Addition (Base 2)
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
def multiply(x1, x2): | |
x1, x2 = min(x1, x2), max(x1, x2) | |
u = 0 | |
while x1 >= 1: | |
if x1 % 2 or x2 % 2: | |
u += x2 | |
x1 /= 2 | |
x2 *= 2 | |
return u |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment