Files
freeCodeCamp/curriculum/challenges/chinese/10-coding-interview-prep/rosetta-code/ethiopian-multiplication.md
2020-09-29 22:09:05 +02:00

2.6 KiB
Raw Blame History

title, id, challengeType, videoUrl, localeTitle
title id challengeType videoUrl localeTitle
Ethiopian multiplication 599d1566a02b571412643b84 5 埃塞俄比亚的乘法

Description

埃塞俄比亚乘法是一种仅使用加法,加倍和减半来乘以整数的方法。

方法:

取两个数字相乘然后将它们写在两列的顶部。在左侧列中反复将最后一个数字减半丢弃任何余数并将结果写入同一列中的最后一个直到您写入值1.在右侧列中重复加倍最后一个数字并写入结果如下。在左侧列显示的同一行中添加结果时停止1.检查生成的表并丢弃左列中的值为偶数的任何行。将右侧列中的值相加,以产生将原始两个数相乘的结果

例如17×34

17 34

将第一列减半:

17 34

8

4

2

1

加倍第二列:

17 34

8 68

4 136

2 272

1 544

第一个单元格为偶数的删除行:

17 34

8 68

4 136

2 272

1 544

将右侧列中的剩余数字相加:

17 34

8 -

4 ---

2 ---

1 544

====

578

所以17乘以34埃塞俄比亚方法是578。

任务:

任务是定义三个命名函数/方法/过程/子例程:

一个将一个整数减半,一个减半整数,一个整数是偶数。

使用这些函数创建一个执行埃塞俄比亚乘法的函数。

Instructions

Tests

tests:
  - text: <code>eth_mult</code>是一个功能。
    testString: assert(typeof eth_mult === 'function');
  - text: '<code>eth_mult(17,34)</code>应该返回<code>578</code> 。'
    testString: assert.equal(eth_mult(17, 34), 578);
  - text: '<code>eth_mult(23,46)</code>应该返回<code>1058</code> 。'
    testString: assert.equal(eth_mult(23, 46), 1058);
  - text: '<code>eth_mult(12,27)</code>应该返回<code>324</code> 。'
    testString: assert.equal(eth_mult(12, 27), 324);
  - text: '<code>eth_mult(56,98)</code>应该返回<code>5488</code> 。'
    testString: assert.equal(eth_mult(56, 98), 5488);
  - text: '<code>eth_mult(63,74)</code>应该返回<code>4662</code> 。'
    testString: assert.equal(eth_mult(63, 74), 4662);

Challenge Seed

function eth_mult (a, b) {
  // Good luck!
}

Solution

// solution required

/section>