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
Raw Blame History

id, title, challengeType, videoUrl, dashedName
id title challengeType videoUrl dashedName
5900f3851000cf542c50fe98 问题251000位斐波纳契数 5 problem-25-1000-digit-fibonacci-number

--description--

Fibonacci序列由递归关系定义

F

n

= F

n-1

  • F

n-2

其中F

1

= 1且F

2

= 1。

因此前12个学期将是

F

1

= 1

F

2

= 1

F

3

= 2

F

4

= 3

F

5

= 5

F

6

= 8

F

7

= 13

F

8

= 21

F

9

= 34

F

10

= 55

F

11

= 89

F

12

= 144

第12个学期F

12

是第一个包含三位数的术语。 Fibonacci序列中包含n个数字的第一项的索引是多少?

--hints--

digitFibonacci(5)应该返回21。

assert.strictEqual(digitFibonacci(5), 21);

digitFibonacci(10)应该返回45。

assert.strictEqual(digitFibonacci(10), 45);

digitFibonacci(15)应该返回69。

assert.strictEqual(digitFibonacci(15), 69);

digitFibonacci(20)应该返回93。

assert.strictEqual(digitFibonacci(20), 93);

--seed--

--seed-contents--

function digitFibonacci(n) {

  return n;
}

digitFibonacci(20);

--solutions--

const digitFibonacci = (n) => {
  const digits = (num) => {
    return num.toString().length;
  };
  let f1 = 1;
  let f2 = 1;
  let index = 3;
  while (true) {
    let fn = f1 + f2;
    if (digits(fn) === n) return index;
    [f1, f2] = [f2, fn];
    index++;
  }
};