Skip to content

Instantly share code, notes, and snippets.

@EHDEV
Created March 21, 2015 18:45
Show Gist options
  • Save EHDEV/41493f7423758003b4c9 to your computer and use it in GitHub Desktop.
Save EHDEV/41493f7423758003b4c9 to your computer and use it in GitHub Desktop.
Ancient Ethiopian Multiplication by Addition (Base 2)
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