18 lines
396 B
Text
18 lines
396 B
Text
local function halve(n) return n // 2 end
|
|
|
|
local function double(n) return n * 2 end
|
|
|
|
local function is_even(n) return n % 2 == 0 end
|
|
|
|
local function ethiopian(x, y)
|
|
local sum = 0
|
|
while x >= 1 do
|
|
if !is_even(x) then sum += y end
|
|
x = halve(x)
|
|
y = double(y)
|
|
end
|
|
return sum
|
|
end
|
|
|
|
print($"17 x 34 = {ethiopian(17, 34)}")
|
|
print($"99 x 99 = {ethiopian(99, 99)}")
|