Ethiopian multiplication: Difference between revisions

Content added Content deleted
(Added Wren)
Line 5,259: Line 5,259:
</lang>{{out}}
</lang>{{out}}
578
578

=={{header|Wren}}==
<lang ecmascript>var halve = Fn.new { |n| (n/2).truncate }

var double = Fn.new { |n| n * 2 }

var isEven = Fn.new { |n| n%2 == 0 }

var ethiopian = Fn.new { |x, y|
var sum = 0
while (x >= 1) {
if (!isEven.call(x)) sum = sum + y
x = halve.call(x)
y = double.call(y)
}
return sum
}

System.print("17 x 34 = %(ethiopian.call(17, 34))")
System.print("99 x 99 = %(ethiopian.call(99, 99))")</lang>

{{out}}
<pre>
17 x 34 = 578
99 x 99 = 9801
</pre>


=={{header|x86 Assembly}}==
=={{header|x86 Assembly}}==