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
@ -5,55 +5,61 @@ challengeType: 5
|
||||
forumTopicId: 302301
|
||||
---
|
||||
|
||||
## Description
|
||||
# --description--
|
||||
|
||||
<section id='description'>
|
||||
The least common multiple of 12 and 18 is 36, because 12 is a factor (12 × 3 = 36), and 18 is a factor (18 × 2 = 36), and there is no positive integer less than 36 that has both factors. As a special case, if either *m* or *n* is zero, then the least common multiple is zero. One way to calculate the least common multiple is to iterate all the multiples of *m*, until you find one that is also a multiple of *n*. If you already have *gcd* for [greatest common divisor](<https://rosettacode.org/wiki/greatest common divisor>), then this formula calculates *lcm*. ( \\operatorname{lcm}(m, n) = \\frac{|m \\times n|}{\\operatorname{gcd}(m, n)} )
|
||||
|
||||
The least common multiple of 12 and 18 is 36, because 12 is a factor (12 × 3 = 36), and 18 is a factor (18 × 2 = 36), and there is no positive integer less than 36 that has both factors. As a special case, if either <i>m</i> or <i>n</i> is zero, then the least common multiple is zero.
|
||||
One way to calculate the least common multiple is to iterate all the multiples of <i>m</i>, until you find one that is also a multiple of <i>n</i>.
|
||||
If you already have <i>gcd</i> for <a href="https://rosettacode.org/wiki/greatest common divisor" target="_blank">greatest common divisor</a>, then this formula calculates <i>lcm</i>.
|
||||
\( \operatorname{lcm}(m, n) = \frac{|m \times n|}{\operatorname{gcd}(m, n)} \)
|
||||
# --instructions--
|
||||
|
||||
</section>
|
||||
Compute the least common multiple of an array of integers. Given *m* and *n*, the least common multiple is the smallest positive integer that has both *m* and *n* as factors.
|
||||
|
||||
## Instructions
|
||||
# --hints--
|
||||
|
||||
<section id='instructions'>
|
||||
`LCM` should be a function.
|
||||
|
||||
Compute the least common multiple of an array of integers.
|
||||
Given <i>m</i> and <i>n</i>, the least common multiple is the smallest positive integer that has both <i>m</i> and <i>n</i> as factors.
|
||||
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>LCM</code> should be a function.
|
||||
testString: assert(typeof LCM == 'function');
|
||||
- text: <code>LCM([2, 4, 8])</code> should return a number.
|
||||
testString: assert(typeof LCM([2, 4, 8]) == 'number');
|
||||
- text: <code>LCM([2, 4, 8])</code> should return <code>8</code>.
|
||||
testString: assert.equal(LCM([2, 4, 8]), 8);
|
||||
- text: <code>LCM([4, 8, 12])</code> should return <code>24</code>.
|
||||
testString: assert.equal(LCM([4, 8, 12]), 24);
|
||||
- text: <code>LCM([3, 4, 5, 12, 40])</code> should return <code>120</code>.
|
||||
testString: assert.equal(LCM([3, 4, 5, 12, 40]), 120);
|
||||
- text: <code>LCM([11, 33, 90])</code> should return <code>990</code>.
|
||||
testString: assert.equal(LCM([11, 33, 90]), 990);
|
||||
- text: <code>LCM([-50, 25, -45, -18, 90, 447])</code> should return <code>67050</code>.
|
||||
testString: assert.equal(LCM([-50, 25, -45, -18, 90, 447]), 67050);
|
||||
```js
|
||||
assert(typeof LCM == 'function');
|
||||
```
|
||||
|
||||
</section>
|
||||
`LCM([2, 4, 8])` should return a number.
|
||||
|
||||
## Challenge Seed
|
||||
```js
|
||||
assert(typeof LCM([2, 4, 8]) == 'number');
|
||||
```
|
||||
|
||||
<section id='challengeSeed'>
|
||||
`LCM([2, 4, 8])` should return `8`.
|
||||
|
||||
<div id='js-seed'>
|
||||
```js
|
||||
assert.equal(LCM([2, 4, 8]), 8);
|
||||
```
|
||||
|
||||
`LCM([4, 8, 12])` should return `24`.
|
||||
|
||||
```js
|
||||
assert.equal(LCM([4, 8, 12]), 24);
|
||||
```
|
||||
|
||||
`LCM([3, 4, 5, 12, 40])` should return `120`.
|
||||
|
||||
```js
|
||||
assert.equal(LCM([3, 4, 5, 12, 40]), 120);
|
||||
```
|
||||
|
||||
`LCM([11, 33, 90])` should return `990`.
|
||||
|
||||
```js
|
||||
assert.equal(LCM([11, 33, 90]), 990);
|
||||
```
|
||||
|
||||
`LCM([-50, 25, -45, -18, 90, 447])` should return `67050`.
|
||||
|
||||
```js
|
||||
assert.equal(LCM([-50, 25, -45, -18, 90, 447]), 67050);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function LCM(A) {
|
||||
@ -61,12 +67,7 @@ function LCM(A) {
|
||||
}
|
||||
```
|
||||
|
||||
</div>
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
|
||||
<section id='solution'>
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function LCM(A) {
|
||||
@ -83,5 +84,3 @@ function LCM(A) {
|
||||
return a;
|
||||
}
|
||||
```
|
||||
|
||||
</section>
|
||||
|
Reference in New Issue
Block a user