Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

2.4 KiB
Raw Blame History

id, title, challengeType, videoUrl, dashedName
id title challengeType videoUrl dashedName
5951ed8945deab770972ae56 河内的塔 5 towers-of-hanoi

--description--

任务:

解决河内塔问题。

您的解决方案应该接受光盘数量作为第一个参数,并使用三个字符串来识别三个光盘堆栈中的每一个,例如towerOfHanoi(4, 'A', 'B', 'C') 。该函数应该返回一个包含移动列表的数组数组source - > destination。例如数组[['A', 'C'], ['B', 'A']]表示第一个移动是将光盘从堆栈A移动到C第二个移动是移动一个从堆栈B到A的光盘

--hints--

towerOfHanoi是一个功能。

assert(typeof towerOfHanoi === 'function');

towerOfHanoi(3, ...) 应该返回7招。

assert(res3.length === 7);

towerOfHanoi(3, "A", "B", "C")应返回“A”“B”][“A”“C”][“B”“C”][ “A” “B”][ “C” “A”][ “C” “B”][ “A” “B”“)。

assert.deepEqual(towerOfHanoi(3, 'A', 'B', 'C'), res3Moves);

towerOfHanoi(5, "X", "Y", "Z")第10 towerOfHanoi(5, "X", "Y", "Z")应为Y - > X.

assert.deepEqual(res5[9], ['Y', 'X']);

towerOfHanoi(7, "A", "B", "C")前十个动作是“A”“B”][“A”“C”][“B”“C”][ “A” “B”][ “C” “A”][ “C” “B”][ “A” “B”][ “A” “C”][ “B” “C”][ “B” “A”“)。

assert.deepEqual(towerOfHanoi(7, 'A', 'B', 'C').slice(0, 10), res7First10Moves);

--seed--

--after-user-code--

const res3 = towerOfHanoi(3, 'A', 'B', 'C');
const res3Moves = [['A', 'B'], ['A', 'C'], ['B', 'C'], ['A', 'B'], ['C', 'A'], ['C', 'B'], ['A', 'B']];
const res5 = towerOfHanoi(5, 'X', 'Y', 'Z');
const res7First10Moves = [['A', 'B'], ['A', 'C'], ['B', 'C'], ['A', 'B'], ['C', 'A'], ['C', 'B'], ['A', 'B'], ['A', 'C'], ['B', 'C'], ['B', 'A']];

--seed-contents--

function towerOfHanoi(n, a, b, c) {

  return [[]];
}

--solutions--

function towerOfHanoi(n, a, b, c) {
  const res = [];
  towerOfHanoiHelper(n, a, c, b, res);
  return res;
}

function towerOfHanoiHelper(n, a, b, c, res) {
  if (n > 0) {
    towerOfHanoiHelper(n - 1, a, c, b, res);
    res.push([a, c]);
    towerOfHanoiHelper(n - 1, b, a, c, res);
  }
}