Anonymous user
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
def halver(x):
while x >= 1:
yield x
x
def doubler(x):
while 1:
yield x
x
▲ return x % 2 == 0
def ethiopian(multiplier, multiplicand):
|