Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TApicella/1e440981acd35b53436599829b93a729 to your computer and use it in GitHub Desktop.
Save TApicella/1e440981acd35b53436599829b93a729 to your computer and use it in GitHub Desktop.
RosettaCode- Ethiopian multiplaction created by tapicella - https://repl.it/Ht6L/6
'''
http://rosettacode.org/wiki/Ethiopian_multiplication
Take two numbers to be multiplied and write them down at the top of two columns.
In the left-hand column repeatedly halve the last number, discarding any remainders, and write the result below the last in the same column, until you write a value of 1.
In the right-hand column repeatedly double the last number and write the result below. stop when you add a result in the same row as where the left hand column shows 1.
Examine the table produced and discard any row where the value in the left column is even.
Sum the values in the right-hand column that remain to produce the result of multiplying the original two numbers together
'''
def multiply(x, y):
total = 0
while x > 0:
total = total+y if x%2!=0 else total
x = x//2
y = y*2
return total
print(multiply(17, 34))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment