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,48 +1,70 @@
---
title: Hofstadter Q sequence
id: 59637c4d89f6786115efd814
title: Hofstadter Q sequence
challengeType: 5
forumTopicId: 302287
---
## Description
<section id='description'>
The <a href="https://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter_Q_sequence" title="wp: Hofstadter_sequence#Hofstadter_Q_sequence" target="_blank">Hofstadter Q sequence</a> is defined as:
<span style="left-margin: 2em;">$Q(1)=Q(2)=1, \\ Q(n)=Q\big(n-Q(n-1)\big)+Q\big(n-Q(n-2)), \quad n>2.$</span>
It is defined like the <a href="https://rosettacode.org/wiki/Fibonacci sequence" title="Fibonacci sequence" target="_blank">Fibonacci sequence</a>, but whereas the next term in the Fibonacci sequence is the sum of the previous two terms, in the Q sequence the previous two terms tell you how far to go back in the Q sequence to find the two numbers to sum to make the next term of the sequence.
</section>
# --description--
## Instructions
<section id='instructions'>
Implement the Hofstadter Q Sequence equation as a function. The function should accept number, <code>n</code>, and return an integer.
</section>
The [Hofstadter Q sequence](https://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter_Q_sequence "wp: Hofstadter_sequence#Hofstadter_Q_sequence") is defined as:
## Tests
<section id='tests'>
$Q(1)=Q(2)=1, \\\\ Q(n)=Q\\big(n-Q(n-1)\\big)+Q\\big(n-Q(n-2)), \\quad n>2.$
```yml
tests:
- text: <code>hofstadterQ</code> should be a function.
testString: assert(typeof hofstadterQ === 'function');
- text: <code>hofstadterQ()</code> should return <code>integer</code>
testString: assert(Number.isInteger(hofstadterQ(1000)));
- text: <code>hofstadterQ(1000)</code> should return <code>502</code>
testString: assert.equal(hofstadterQ(testCase[0]), res[0]);
- text: <code>hofstadterQ(1500)</code> should return <code>755</code>
testString: assert.equal(hofstadterQ(testCase[1]), res[1]);
- text: <code>hofstadterQ(2000)</code> should return <code>1005</code>
testString: assert.equal(hofstadterQ(testCase[2]), res[2]);
- text: <code>hofstadterQ(2500)</code> should return <code>1261</code>
testString: assert.equal(hofstadterQ(testCase[3]), res[3]);
It is defined like the [Fibonacci sequence](<https://rosettacode.org/wiki/Fibonacci sequence> "Fibonacci sequence"), but whereas the next term in the Fibonacci sequence is the sum of the previous two terms, in the Q sequence the previous two terms tell you how far to go back in the Q sequence to find the two numbers to sum to make the next term of the sequence.
# --instructions--
Implement the Hofstadter Q Sequence equation as a function. The function should accept number, `n`, and return an integer.
# --hints--
`hofstadterQ` should be a function.
```js
assert(typeof hofstadterQ === 'function');
```
</section>
`hofstadterQ()` should return `integer`
## Challenge Seed
<section id='challengeSeed'>
```js
assert(Number.isInteger(hofstadterQ(1000)));
```
<div id='js-seed'>
`hofstadterQ(1000)` should return `502`
```js
assert.equal(hofstadterQ(testCase[0]), res[0]);
```
`hofstadterQ(1500)` should return `755`
```js
assert.equal(hofstadterQ(testCase[1]), res[1]);
```
`hofstadterQ(2000)` should return `1005`
```js
assert.equal(hofstadterQ(testCase[2]), res[2]);
```
`hofstadterQ(2500)` should return `1261`
```js
assert.equal(hofstadterQ(testCase[3]), res[3]);
```
# --seed--
## --after-user-code--
```js
const testCase = [1000, 1500, 2000, 2500];
const res = [502, 755, 1005, 1261];
```
## --seed-contents--
```js
function hofstadterQ(n) {
@ -51,24 +73,7 @@ function hofstadterQ(n) {
}
```
</div>
### After Test
<div id='js-teardown'>
```js
const testCase = [1000, 1500, 2000, 2500];
const res = [502, 755, 1005, 1261];
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
function hofstadterQ (n) {
@ -83,7 +88,4 @@ function hofstadterQ (n) {
};
return Q(n);
}
```
</section>