Ethiopian multiplication: Difference between revisions

→‎{{header|Python}}: Almost the cream of Python...
(→‎{{header|Python}}: Fully comply with task definition (i hope) :-))
(→‎{{header|Python}}: Almost the cream of Python...)
Line 2,349:
return result</lang>
 
Using lambdas, a higher-order function, generators, a list comprehension, izip and a generator expression.
 
<lang python>from itertools import izip
Line 2,357:
even = lambda x: x % 2 == 0
 
def make_generator(predicate, function):
def halver(x):
whiledef generator(x >= 1):
yieldwhile predicate(x):
x = halve( yield x)
x = doublefunction(x)
return generator
 
halver = make_generator(lambda x: x >= 1, halve)
def doubler(x):
doubler = make_generator(lambda x: True, double)
while 1:
yield x
x = double(x)
 
def ethiopian(multiplier, multiplicand):
Anonymous user