Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

1.7 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
ae9defd7acaf69703ab432ea Smallest Common Multiple 5 16075 smallest-common-multiple

--description--

Find the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters.

The range will be an array of two numbers that will not necessarily be in numerical order.

For example, if given 1 and 3, find the smallest common multiple of both 1 and 3 that is also evenly divisible by all numbers between 1 and 3. The answer here would be 6.

--hints--

smallestCommons([1, 5]) should return a number.

assert.deepEqual(typeof smallestCommons([1, 5]), 'number');

smallestCommons([1, 5]) should return 60.

assert.deepEqual(smallestCommons([1, 5]), 60);

smallestCommons([5, 1]) should return 60.

assert.deepEqual(smallestCommons([5, 1]), 60);

smallestCommons([2, 10]) should return 2520.

assert.deepEqual(smallestCommons([2, 10]), 2520);

smallestCommons([1, 13]) should return 360360.

assert.deepEqual(smallestCommons([1, 13]), 360360);

smallestCommons([23, 18]) should return 6056820.

assert.deepEqual(smallestCommons([23, 18]), 6056820);

--seed--

--seed-contents--

function smallestCommons(arr) {
  return arr;
}


smallestCommons([1,5]);

--solutions--

function gcd(a, b) {
    while (b !== 0) {
        a = [b, b = a % b][0];
    }
    return a;
}

function lcm(a, b) {
    return (a * b) / gcd(a, b);
}

function smallestCommons(arr) {
  arr.sort(function(a,b) {return a-b;});
  var rng = [];
  for (var i = arr[0]; i <= arr[1]; i++) {
    rng.push(i);
  }
  return rng.reduce(lcm);
}