ethiopian_multiplication.sf 266 B

1234567891011121314151617
  1. #!/usr/bin/ruby
  2. func double (n) { n * 2 };
  3. func halve (n) { int(n / 2) };
  4. func ethiopic_mult(a, b) {
  5. var r = 0;
  6. while (a > 0) {
  7. a.is_even || (r += b);
  8. a = halve(a);
  9. b = double(b);
  10. };
  11. return r;
  12. }
  13. say ethiopic_mult(17, 34);