5 ms·
In Ruby: # Ethiopian Multiplication # usage: ruby em.rb 673 7 m, n = ARGV.map(&:to_i) product = 0 while m >= 1 puts "%4d : %4d %s" % [m, n, m.eve
by Kafka 14y ago
In Ruby:
# Ethiopian Multiplication
# usage: ruby em.rb 673 7
m, n = ARGV.map(&:to_i)
product = 0
while m >= 1
puts "%4d : %4d %s" % [m, n, m.even? ? "Ignore" : ""]
product += n unless m.even?
m = m / 2
n = n * 2
end
puts "Product: #{product}"
https://gist.github.com/3660240 https://gist.github.com/3660240