Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -1,28 +1,31 @@
|
|||
tutor = True
|
||||
|
||||
def halve(x):
|
||||
return x//2
|
||||
return x // 2
|
||||
|
||||
def double(x):
|
||||
return x*2
|
||||
return x * 2
|
||||
|
||||
def even(x):
|
||||
return not x % 2
|
||||
|
||||
def ethiopian(multiplier, multiplicand):
|
||||
if tutor:
|
||||
print( "Ethiopian multiplication of %i and %i" %
|
||||
(multiplier, multiplicand) )
|
||||
print("Ethiopian multiplication of %i and %i" %
|
||||
(multiplier, multiplicand))
|
||||
result = 0
|
||||
while multiplier >= 1:
|
||||
if even(multiplier):
|
||||
if tutor: print( "%4i %6i STRUCK" %
|
||||
(multiplier, multiplicand) )
|
||||
if tutor:
|
||||
print("%4i %6i STRUCK" %
|
||||
(multiplier, multiplicand))
|
||||
else:
|
||||
if tutor: print( "%4i %6i KEPT" %
|
||||
(multiplier, multiplicand) )
|
||||
if tutor:
|
||||
print("%4i %6i KEPT" %
|
||||
(multiplier, multiplicand))
|
||||
result += multiplicand
|
||||
multiplier = halve(multiplier)
|
||||
multiplicand = double(multiplicand)
|
||||
if tutor: print()
|
||||
if tutor:
|
||||
print()
|
||||
return result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue