Instruções

Multiplicação etíope

A multiplicação etíope é um método de multiplicação de inteiros usando apenas adição, duplicação e divisão pela metade. Método: <ol> <li>Take two numbers to be multiplied and write them down at the top of two columns</li> <li>In the left-hand column repeatedly halve the last number, discarding any remainders, and write the result below the last in the same column, until you write a value of <code>1</code></li> <li>In the right-hand column repeatedly double the last number and write the result below. stop when you add a result in the same row as where the left hand column shows <code>1</code></li> <li>Examine the table produced and discard any row where the value in the left column is even</li> <li>Sum the values in the right-hand column that remain to produce the result of multiplying the original two numbers together</li> </ol> Por exemplo: 17 × 34 <pre>17 34 </pre> Dividindo o valor da primeira coluna pela metade: <pre>17 34 8 4 2 1 </pre> Duplicando o valor da segunda coluna: <pre>17 34 8 68 4 136 2 272 1 544 </pre> Removendo as linhas em que a primeira célula é par: <pre>17 34 8 <strike>68</strike> 4 <strike>136</strike> 2 <strike>272</strike> 1 544 </pre> Somando os números restantes na coluna da direita: <!-- markdownlint-disable MD003 --> <pre>17 34 8 -- 4 --- 2 --- 1 544 ==== 578 </pre> <!-- markdownlint-enable MD003 --> Temos, então, que 17 multiplicado por 34, pelo método etíope, é 578.

O que fazer:

A tarefa é definir três funções/métodos/procedimentos/sub-rotinas nomeadas: <ol> <li>one to halve an integer,</li> <li>one to double an integer, and</li> <li>one to state if an integer is even</li> </ol> Use essas funções para criar uma função que faça uma multiplicação etíope. <!-- markdownlint-disable MD046-->

Critérios de Aceitação:

Testes:

  • `eth_mult` deve ser uma função.
  • `eth_mult(17,34)` deve retornar `578`.
  • `eth_mult(23,46)` deve retornar `1058`.
  • `eth_mult(12,27)` deve retornar `324`.
  • `eth_mult(56,98)` deve retornar `5488`.
  • `eth_mult(63,74)` deve retornar `4662`.

Console