Skip to content

Instantly share code, notes, and snippets.

@blackmann
Created June 14, 2014 13:26
Show Gist options
  • Save blackmann/f8cca0d7507d7b833ca4 to your computer and use it in GitHub Desktop.
Save blackmann/f8cca0d7507d7b833ca4 to your computer and use it in GitHub Desktop.
Egyptian Multiplier
#Egyptian multiplier
def main():
numbers = (raw_input('Enter 2 ints: ')).split(' ')
numbers = map(int, numbers)
j, k= numbers
a, b = map(abs, numbers)
result = 0
while b>0:
if b%2!=0:
print '[*]b is even...adding %s to give: %s' %(a, result)
result += a
b /=2
a *= 2
if ((j<0)and(k>0)) or ((j>0)and(k<0)):
print -result
else:
print result
main()
while raw_input('Again?: ') in 'yY':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment