Created
June 14, 2014 13:26
-
-
Save blackmann/f8cca0d7507d7b833ca4 to your computer and use it in GitHub Desktop.
Egyptian Multiplier
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
#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