Jump to content

Ethiopian multiplication: Difference between revisions

Added Wren
(Added Wren)
Line 5,259:
</lang>{{out}}
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}}==
9,486

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.