Skip to content

Instantly share code, notes, and snippets.

@jonelf
Created November 23, 2012 09:57
Show Gist options
  • Select an option

  • Save jonelf/4134839 to your computer and use it in GitHub Desktop.

Select an option

Save jonelf/4134839 to your computer and use it in GitHub Desktop.
Ethiopian Multiplication
m = 673
n = 7
product = 0
console.log "#{m} times #{n} by Ethiopian Multiplication\n"
while m >= 1
product += n unless m % 2 == 0
m = Math.floor(m / 2)
n = Math.floor(n * 2)
console.log "#{m} : #{n} \t#{if m % 2 == 0 then 'Ignore' else ''}"
console.log "\nProduct: #{product}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment