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

2.3 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
5a23c84252665b21eecc7eca Kaprekar numbers 5 302296 kaprekar-numbers

--description--

A positive integer is a Kaprekar number if:

  • It is 1, or,
  • The decimal representation of its square may be split once into two parts consisting of positive integers which sum to the original number.

Note that a split resulting in a part consisting purely of 0s is not valid, as 0 is not considered positive.Example

Kaprekar numbers:

  • 2223 is a Kaprekar number, as 2223 * 2223 = 4941729, 4941729 may be split to 494 and 1729, and 494 + 1729 = 2223
  • The series of Kaprekar numbers is known as A006886, and begins as 1, 9, 45, 55, ...

--instructions--

Write a function that takes a number n, a base bs, and returns true if the number is a Kaprekar number for the given base. Otherwise, the function returns false.

--hints--

isKaprekar should be a function.

assert(typeof isKaprekar == 'function');

isKaprekar(1, 10) should return a boolean.

assert(typeof isKaprekar(1, 10) == 'boolean');

isKaprekar(1, 10) should return true.

assert.equal(isKaprekar(1, 10), true);

isKaprekar(9, 10) should return true.

assert.equal(isKaprekar(9, 10), true);

isKaprekar(2223, 10) should return true.

assert.equal(isKaprekar(2223, 10), true);

isKaprekar(22823, 10) should return false.

assert.equal(isKaprekar(22823, 10), false);

isKaprekar(9, 17) should return false.

assert.equal(isKaprekar(9, 17), false);

isKaprekar(225, 17) should return true.

assert.equal(isKaprekar(225, 17), true);

isKaprekar(999, 17) should return false.

assert.equal(isKaprekar(999, 17), false);

--seed--

--seed-contents--

function isKaprekar(n, bs) {

}

--solutions--

function isKaprekar(n, bs) {
  if (n < 1) return false;
  if (n == 1) return true;
  for (var a = n * n, b = 0, s = 1; a; s *= bs) {
    b += (a % bs) * s;
    a = Math.floor(a / bs);
    if (b && a + b == n) return true;
  }
  return false;
}