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,47 +1,59 @@
---
title: Ackermann function
id: 594810f028c0303b75339acf
title: Ackermann function
challengeType: 5
forumTopicId: 302223
---
## Description
<section id='description'>
# --description--
The Ackermann function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree.
The Ackermann function is usually defined as follows:
$A(m, n) = \begin{cases} n+1 & \mbox{if } m = 0 \\ A(m-1, 1) & \mbox{if } m > 0 \mbox{ and } n = 0 \\ A(m-1, A(m, n-1)) & \mbox{if } m > 0 \mbox{ and } n > 0. \end{cases}$
$A(m, n) = \\begin{cases} n+1 & \\mbox{if } m = 0 \\\\ A(m-1, 1) & \\mbox{if } m > 0 \\mbox{ and } n = 0 \\\\ A(m-1, A(m, n-1)) & \\mbox{if } m > 0 \\mbox{ and } n > 0. \\end{cases}$
Its arguments are never negative and it always terminates.
</section>
## Instructions
<section id='instructions'>
# --instructions--
Write a function which returns the value of $A(m, n)$. Arbitrary precision is preferred (since the function grows so quickly), but not required.
</section>
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: <code>ack</code> should be a function.
testString: assert(typeof ack === 'function');
- text: <code>ack(0, 0)</code> should return 1.
testString: assert(ack(0, 0) === 1);
- text: <code>ack(1, 1)</code> should return 3.
testString: assert(ack(1, 1) === 3);
- text: <code>ack(2, 5)</code> should return 13.
testString: assert(ack(2, 5) === 13);
- text: <code>ack(3, 3)</code> should return 61.
testString: assert(ack(3, 3) === 61);
`ack` should be a function.
```js
assert(typeof ack === 'function');
```
</section>
`ack(0, 0)` should return 1.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(ack(0, 0) === 1);
```
<div id='js-seed'>
`ack(1, 1)` should return 3.
```js
assert(ack(1, 1) === 3);
```
`ack(2, 5)` should return 13.
```js
assert(ack(2, 5) === 13);
```
`ack(3, 3)` should return 61.
```js
assert(ack(3, 3) === 61);
```
# --seed--
## --seed-contents--
```js
function ack(m, n) {
@ -49,21 +61,10 @@ function ack(m, n) {
}
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
function ack(m, n) {
return m === 0 ? n + 1 : ack(m - 1, n === 0 ? 1 : ack(m, n - 1));
}
```
</section>