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.6 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
5a23c84252665b21eecc7ec1 Iterated digits squaring 5 302291 iterated-digits-squaring

--description--

If you add the square of the digits of a Natural number (an integer bigger than zero), you always end with either 1 or 89:

15 -> 26 -> 40 -> 16 -> 37 -> 58 -> 89
7 -> 49 -> 97 -> 130 -> 10 -> 1

--instructions--

Write a function that takes a number as a parameter and returns 1 or 89 after performing the mentioned process.

--hints--

iteratedSquare should be a function.

assert(typeof iteratedSquare == 'function');

iteratedSquare(4) should return a number.

assert(typeof iteratedSquare(4) == 'number');

iteratedSquare(4) should return 89.

assert.equal(iteratedSquare(4), 89);

iteratedSquare(7) should return 1.

assert.equal(iteratedSquare(7), 1);

iteratedSquare(15) should return 89.

assert.equal(iteratedSquare(15), 89);

iteratedSquare(20) should return 89.

assert.equal(iteratedSquare(20), 89);

iteratedSquare(70) should return 1.

assert.equal(iteratedSquare(70), 1);

iteratedSquare(100) should return 1.

assert.equal(iteratedSquare(100), 1);

--seed--

--seed-contents--

function iteratedSquare(n) {

}

--solutions--

function iteratedSquare(n) {
    var total;
    while (n != 89 && n != 1) {
        total = 0;
        while (n > 0) {
            total += Math.pow(n % 10, 2);
            n = Math.floor(n/10);
        }
        n = total;
    }
    return n;
}