def halve(x)   x/2  end
def double(x)  x*2  end


def ethiopian_multiply(a, b)
  product = 0
  while a >= 1 
    p [a, b, a.even?? : ] if $DEBUG
    product += b unless a.even?
    a = halve(a)
    b = double(b)
  end
  product
end


def rec_ethiopian_multiply(a, b)
  return 0 if a < 1
  p [a, b, a.even?? : ] if $DEBUG
  (a.even?? 0: b) + rec_ethiopian_multiply(halve(a), double(b))
end

$DEBUG = true   
a, b = 20, 5
puts ; puts