Ethiopian multiplication: Difference between revisions

→‎{{header|Python}}: Fully comply with task definition (i hope) :-)
(→‎{{header|Python}}: Final (I hope) cleanup. Sorry for the many edits :-))
(→‎{{header|Python}}: Fully comply with task definition (i hope) :-))
Line 2,349:
return result</lang>
 
Using lambdas, generators, a list comprehension, izip and a generator expression.
 
<lang python>from itertools import izip
 
halve = lambda x: x // 2
double = lambda x: x * 2
even = lambda returnx: x % 2 == 0
 
def halver(x):
while x >= 1:
yield x
x /= 2halve(x)
 
def doubler(x):
while 1:
yield x
x *= 2double(x)
 
def even(x):
return x % 2 == 0
 
def ethiopian(multiplier, multiplicand):
Anonymous user