Ethiopian multiplication: Difference between revisions
Content added Content deleted
(→{{header|Python}}: Use takewhile) |
m (→{{header|Python}}: -r -> -s) |
||
Line 2,401: | Line 2,401: | ||
arg = function(arg) |
arg = function(arg) |
||
halves = lambda x: takewhile(lambda v: v >= 1, iterate(halve, x)) |
|||
doubles = lambda x: iterate(double, x) |
|||
def ethiopian(multiplier, multiplicand): |
def ethiopian(multiplier, multiplicand): |
||
table = [(p, q) for p, q in |
table = [(p, q) for p, q in |
||
izip( |
izip(halves(multiplier), doubles(multiplicand))] |
||
result = sum(q for p, q in table if not even(p)) |
result = sum(q for p, q in table if not even(p)) |
||
return result</lang> |
return result</lang> |