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,51 +1,95 @@
---
title: Emirp primes
id: 599d0ba974141b0f508b37d5
title: Emirp primes
challengeType: 5
forumTopicId: 302253
---
## Description
<section id='description'>
An emirp (<strong>prime</strong> spelled backwards) are primes that when reversed (in their decimal representation) are a different prime.
</section>
# --description--
An emirp (**prime** spelled backwards) are primes that when reversed (in their decimal representation) are a different prime.
# --instructions--
Write a function that:
## Instructions
<section id='instructions'>
Write a function that:
<ul>
<li>Shows the first <code>n</code> emirp numbers.</li>
<li>Shows the emirp numbers in a range.</li>
<li>Shows the number of emirps in a range.</li>
<li>Shows the <code>n<sup>th</sup></code> emirp number.</li>
</ul>
The function should accept two parameters. The first will receive <code>n</code> or the range as an array. The second will receive a boolean, that specifies if the function returns the emirps as an array or a single number (the number of primes in the range or the <code>n<sup>th</sup></code> prime). According to the parameters the function should return an array or a number.
</section>
## Tests
<section id='tests'>
The function should accept two parameters. The first will receive `n` or the range as an array. The second will receive a boolean, that specifies if the function returns the emirps as an array or a single number (the number of primes in the range or the <code>n<sup>th</sup></code> prime). According to the parameters the function should return an array or a number.
```yml
tests:
- text: <code>emirps</code> should be a function.
testString: assert(typeof emirps === 'function');
- text: <code>emirps(20,true)</code> should return <code>[13,17,31,37,71,73,79,97,107,113,149,157,167,179,199,311,337,347,359,389]</code>
testString: assert.deepEqual(emirps(20, true), [13, 17, 31, 37, 71, 73, 79, 97, 107, 113, 149, 157, 167, 179, 199, 311, 337, 347, 359, 389]);
- text: <code>emirps(1000)</code> should return <code>70529</code>
testString: assert.deepEqual(emirps(1000), 70529);
- text: <code>emirps([7700,8000],true)</code> should return <code>[7717,7757,7817,7841,7867,7879,7901,7927,7949,7951,7963]</code>
testString: assert.deepEqual(emirps([7700, 8000], true), [7717, 7757, 7817, 7841, 7867, 7879, 7901, 7927, 7949, 7951, 7963]);
- text: <code>emirps([7700,8000],true)</code> should return <code>11</code>
testString: assert.deepEqual(emirps([7700, 8000], false), 11);
# --hints--
`emirps` should be a function.
```js
assert(typeof emirps === 'function');
```
</section>
`emirps(20,true)` should return `[13,17,31,37,71,73,79,97,107,113,149,157,167,179,199,311,337,347,359,389]`
## Challenge Seed
<section id='challengeSeed'>
```js
assert.deepEqual(emirps(20, true), [
13,
17,
31,
37,
71,
73,
79,
97,
107,
113,
149,
157,
167,
179,
199,
311,
337,
347,
359,
389
]);
```
<div id='js-seed'>
`emirps(1000)` should return `70529`
```js
assert.deepEqual(emirps(1000), 70529);
```
`emirps([7700,8000],true)` should return `[7717,7757,7817,7841,7867,7879,7901,7927,7949,7951,7963]`
```js
assert.deepEqual(emirps([7700, 8000], true), [
7717,
7757,
7817,
7841,
7867,
7879,
7901,
7927,
7949,
7951,
7963
]);
```
`emirps([7700,8000],true)` should return `11`
```js
assert.deepEqual(emirps([7700, 8000], false), 11);
```
# --seed--
## --seed-contents--
```js
function emirps(n) {
@ -53,26 +97,18 @@ function emirps(n) {
}
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
function emirps(num, showEmirps)
{
const is_prime = function(n)
{
{
if (!(n % 2) || !(n % 3)) return false;
let p = 1;
while (p * p < n)
{ if (n % (p += 4) == 0 || n % (p += 2) == 0)
{ return false; } }
{ if (n % (p += 4) == 0 || n % (p += 2) == 0)
{ return false; } }
return true;
};
const is_emirp = function(n) {
@ -98,7 +134,4 @@ function emirps(num, showEmirps)
return arr.length;
}
}
```
</section>