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

3.1 KiB
Raw Blame History

id, title, challengeType, videoUrl, dashedName
id title challengeType videoUrl dashedName
59622f89e4e137560018a40e Hofstadter图 - 图序列 5 hofstadter-figure-figure-sequences

--description--

这两个正整数序列定义为:

$$ R1= 1 \; \ S1= 2 \\ Rn= Rn-1+ Sn-1\ quad n> 1. $$

序列$ Sn$进一步定义为$ Rn$中不存在的正整数序列。

序列$ R $开始:

1,3,7,12,18 ......

序列$ S $开始:

2,4,5,6,8 ......

任务创建两个名为ffr和ffs的函数当给定n分别返回Rn或Sn注意R1= 1且S1= 2以避免逐个错误 。不应假设n的最大值。 Sloane的A005228A030124Wolfram MathWorld维基百科: Hofstadter图 - 图序列

--hints--

ffr是一个功能。

assert(typeof ffr === 'function');

ffs是一个函数。

assert(typeof ffs === 'function');

ffr应该返回整数。

assert(Number.isInteger(ffr(1)));

ffs应该返回整数。

assert(Number.isInteger(ffs(1)));

ffr()应该返回69

assert.equal(ffr(ffrParamRes[0][0]), ffrParamRes[0][1]);

ffr()应返回1509

assert.equal(ffr(ffrParamRes[1][0]), ffrParamRes[1][1]);

ffr()应返回5764

assert.equal(ffr(ffrParamRes[2][0]), ffrParamRes[2][1]);

ffr()应返回526334

assert.equal(ffr(ffrParamRes[3][0]), ffrParamRes[3][1]);

ffs()应该返回14

assert.equal(ffs(ffsParamRes[0][0]), ffsParamRes[0][1]);

ffs()应该返回59

assert.equal(ffs(ffsParamRes[1][0]), ffsParamRes[1][1]);

ffs()应该返回112

assert.equal(ffs(ffsParamRes[2][0]), ffsParamRes[2][1]);

ffs()应该返回1041

assert.equal(ffs(ffsParamRes[3][0]), ffsParamRes[3][1]);

--seed--

--after-user-code--

const ffrParamRes = [[10, 69], [50, 1509], [100, 5764], [1000, 526334]];
const ffsParamRes = [[10, 14], [50, 59], [100, 112], [1000, 1041]];

--seed-contents--

function ffr(n) {
  return n;
}

function ffs(n) {
  return n;
}

--solutions--

const R = [null, 1];
const S = [null, 2];

function extendSequences (n) {
  let current = Math.max(R[R.length - 1], S[S.length - 1]);
  let i;
  while (R.length <= n || S.length <= n) {
    i = Math.min(R.length, S.length) - 1;
    current += 1;
    if (current === R[i] + S[i]) {
      R.push(current);
    } else {
      S.push(current);
    }
  }
}

function ffr (n) {
  extendSequences(n);
  return R[n];
}

function ffs (n) {
  extendSequences(n);
  return S[n];
}