Feat: add new Markdown parser (#39800)

and change all the challenges to new `md` format.
This commit is contained in:
Oliver Eyton-Williams
2020-11-27 19:02:05 +01:00
committed by GitHub
parent a07f84c8ec
commit 0bd52f8bd1
2580 changed files with 113436 additions and 111979 deletions

View File

@ -1,60 +1,55 @@
---
title: Towers of Hanoi
id: 5951ed8945deab770972ae56
title: Towers of Hanoi
challengeType: 5
forumTopicId: 302341
---
## Description
<section id='description'>
Solve the <a href="https://en.wikipedia.org/wiki/Towers_of_Hanoi" title="wp: Towers_of_Hanoi" target="_blank">Towers of Hanoi</a> problem.</p>
Your solution should accept the number of discs as the first parameters, and three string used to identify each of the three stacks of discs, for example <code>towerOfHanoi(4, 'A', 'B', 'C')</code>. The function should return an array of arrays containing the list of moves, source -> destination.
For example, the array <code>[['A', 'C'], ['B', 'A']]</code> indicates that the 1st move was to move a disc from stack A to C, and the 2nd move was to move a disc from stack B to A.
</p>
</section>
# --description--
## Instructions
<section id='instructions'>
Solve the [Towers of Hanoi](https://en.wikipedia.org/wiki/Towers_of_Hanoi "wp: Towers_of_Hanoi") problem.
</section>
Your solution should accept the number of discs as the first parameters, and three string used to identify each of the three stacks of discs, for example `towerOfHanoi(4, 'A', 'B', 'C')`. The function should return an array of arrays containing the list of moves, source -> destination.
## Tests
<section id='tests'>
For example, the array `[['A', 'C'], ['B', 'A']]` indicates that the 1st move was to move a disc from stack A to C, and the 2nd move was to move a disc from stack B to A.
```yml
tests:
- text: <code>towerOfHanoi</code> should be a function.
testString: assert(typeof towerOfHanoi === 'function');
- text: <code>towerOfHanoi(3, ...)</code> should return 7 moves.
testString: assert(res3.length === 7);
- text: <code>towerOfHanoi(3, 'A', 'B', 'C')</code> should return <code>[['A','B'], ['A','C'], ['B','C'], ['A','B'], ['C','A'], ['C','B'], ['A','B']]</code>.
testString: assert.deepEqual(towerOfHanoi(3, 'A', 'B', 'C'), res3Moves);
- text: <code>towerOfHanoi(5, "X", "Y", "Z")</code> 10th move should be Y -> X.
testString: assert.deepEqual(res5[9], ['Y', 'X']);
- text: <code>towerOfHanoi(7, 'A', 'B', 'C')</code> first ten moves should be <code>[['A','B'], ['A','C'], ['B','C'], ['A','B'], ['C','A'], ['C','B'], ['A','B'], ['A','C'], ['B','C'], ['B','A']]</code>
testString: assert.deepEqual(towerOfHanoi(7, 'A', 'B', 'C').slice(0, 10), res7First10Moves);
<p></p>
```
# --hints--
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
`towerOfHanoi` should be a function.
```js
function towerOfHanoi(n, a, b, c) {
return [[]];
}
assert(typeof towerOfHanoi === 'function');
```
</div>
`towerOfHanoi(3, ...)` should return 7 moves.
```js
assert(res3.length === 7);
```
### After Test
<div id='js-teardown'>
`towerOfHanoi(3, 'A', 'B', 'C')` should return `[['A','B'], ['A','C'], ['B','C'], ['A','B'], ['C','A'], ['C','B'], ['A','B']]`.
```js
assert.deepEqual(towerOfHanoi(3, 'A', 'B', 'C'), res3Moves);
```
`towerOfHanoi(5, "X", "Y", "Z")` 10th move should be Y -> X.
```js
assert.deepEqual(res5[9], ['Y', 'X']);
```
`towerOfHanoi(7, 'A', 'B', 'C')` first ten moves should be `[['A','B'], ['A','C'], ['B','C'], ['A','B'], ['C','A'], ['C','B'], ['A','B'], ['A','C'], ['B','C'], ['B','A']]`
```js
assert.deepEqual(towerOfHanoi(7, 'A', 'B', 'C').slice(0, 10), res7First10Moves);
```
# --seed--
## --after-user-code--
```js
const res3 = towerOfHanoi(3, 'A', 'B', 'C');
@ -63,13 +58,16 @@ 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']];
```
</div>
## --seed-contents--
</section>
```js
function towerOfHanoi(n, a, b, c) {
## Solution
<section id='solution'>
return [[]];
}
```
# --solutions--
```js
function towerOfHanoi(n, a, b, c) {
@ -85,7 +83,4 @@ function towerOfHanoiHelper(n, a, b, c, res) {
towerOfHanoiHelper(n - 1, b, a, c, res);
}
}
```
</section>