Feat: add new Markdown parser (#39800)
and change all the challenges to new `md` format.
This commit is contained in:
committed by
GitHub
parent
a07f84c8ec
commit
0bd52f8bd1
@ -1,53 +1,61 @@
|
||||
---
|
||||
title: Hailstone sequence
|
||||
id: 595608ff8bcd7a50bd490181
|
||||
title: Hailstone sequence
|
||||
challengeType: 5
|
||||
forumTopicId: 302279
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
The Hailstone sequence of numbers can be generated from a starting positive integer, <code>n</code> by:
|
||||
# --description--
|
||||
|
||||
The Hailstone sequence of numbers can be generated from a starting positive integer, `n` by:
|
||||
|
||||
<ul>
|
||||
<li>If <code>n</code> is <code>1</code> then the sequence ends</li>
|
||||
<li>If <code>n</code> is <code>even</code> then the next <code>n</code> of the sequence <code>= n/2</code></li>
|
||||
<li>If <code>n</code> is <code>odd</code> then the next <code>n</code> of the sequence <code>= (3 * n) + 1</code></li>
|
||||
</ul>
|
||||
The (unproven) <a href="https://en.wikipedia.org/wiki/Collatz conjecture" title="wp: Collatz conjecture" target="_blank">Collatz conjecture</a> is that the hailstone sequence for any starting number always terminates.
|
||||
The hailstone sequence is also known as hailstone numbers (because the values are usually subject to multiple descents and ascents like hailstones in a cloud), or as the Collatz sequence.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
The (unproven) [Collatz conjecture](<https://en.wikipedia.org/wiki/Collatz conjecture> "wp: Collatz conjecture") is that the hailstone sequence for any starting number always terminates.
|
||||
|
||||
The hailstone sequence is also known as hailstone numbers (because the values are usually subject to multiple descents and ascents like hailstones in a cloud), or as the Collatz sequence.
|
||||
|
||||
# --instructions--
|
||||
|
||||
<ol>
|
||||
<li>Create a routine to generate the hailstone sequence for a number</li>
|
||||
<li>Use the routine to show that the hailstone sequence for the number 27 has 112 elements starting with <code>27, 82, 41, 124</code> and ending with <code>8, 4, 2, 1</code></li>
|
||||
<li>Show the number less than 100,000 which has the longest hailstone sequence together with that sequence's length. (But don't show the actual sequence!)</li>
|
||||
</ol>
|
||||
<strong>See also:</strong>
|
||||
|
||||
**See also:**
|
||||
|
||||
<ul>
|
||||
<li><a href="https://xkcd.com/710" target="_blank">xkcd</a> (humourous).</li>
|
||||
<li><a href='https://xkcd.com/710' target='_blank'>xkcd</a> (humourous).</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
# --hints--
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>hailstoneSequence</code> should be a function.
|
||||
testString: assert(typeof hailstoneSequence === 'function');
|
||||
- text: <code>hailstoneSequence()</code> should return <code>[[27,82,41,124,8,4,2,1], [351, 77031]]</code>
|
||||
testString: assert.deepEqual(hailstoneSequence(), res);
|
||||
`hailstoneSequence` should be a function.
|
||||
|
||||
```js
|
||||
assert(typeof hailstoneSequence === 'function');
|
||||
```
|
||||
|
||||
</section>
|
||||
`hailstoneSequence()` should return `[[27,82,41,124,8,4,2,1], [351, 77031]]`
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
```js
|
||||
assert.deepEqual(hailstoneSequence(), res);
|
||||
```
|
||||
|
||||
<div id='js-seed'>
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
const res = [[27, 82, 41, 124, 8, 4, 2, 1], [351, 77031]];
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function hailstoneSequence() {
|
||||
@ -58,23 +66,7 @@ function hailstoneSequence() {
|
||||
}
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
const res = [[27, 82, 41, 124, 8, 4, 2, 1], [351, 77031]];
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function hailstoneSequence () {
|
||||
@ -108,7 +100,4 @@ function hailstoneSequence () {
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
Reference in New Issue
Block a user