* 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>
2.7 KiB
2.7 KiB
id, title, challengeType, videoUrl, dashedName
id | title | challengeType | videoUrl | dashedName |
---|---|---|---|---|
5949b579404977fbaefcd736 | 90亿上帝的名字整数 | 5 | 9-billion-names-of-god-the-integer |
--description--
这项任务是Arthur C. Clarke的短篇小说改编 。
(求解者应该意识到完成这项任务的后果。)
详细说明,指定“名称”的含义:
整数1有1个名称“1”。
整数2有2个名称“1 + 1”和“2”。
整数3具有3个名称“1 + 1 + 1”,“2 + 1”和“3”。
整数4具有5个名称“1 + 1 + 1 + 1”,“2 + 1 + 1”,“2 + 2”,“3 + 1”,“4”。
整数5有7个名称“1 + 1 + 1 + 1 + 1”,“2 + 1 + 1 + 1”,“2 + 2 + 1”,“3 + 1 + 1”,“3 + 2”, “4 + 1”,“5”。
这可以通过以下形式显示:
1 1 1 1 1 1 1 2 1 1 1 2 2 1 1 1 3 3 2 1 1
其中row $ n $对应于整数$ n $,而行$ m $中从左到右的每列$ C $对应于以$ C $开头的名称数。
(可选)请注意$ n $ -th行$ P(n)$的总和是整数分区函数 。
任务实现一个返回$ n $ -th行之和的函数。
--hints--
numberOfNames
是一个函数。
assert(typeof numberOfNames === 'function');
numberOfNames(5)
应该等于7。
assert.equal(numberOfNames(5), 7);
numberOfNames(12)
应该等于77。
assert.equal(numberOfNames(12), 77);
numberOfNames(18)
应该等于385。
assert.equal(numberOfNames(18), 385);
numberOfNames(23)
应该等于1255。
assert.equal(numberOfNames(23), 1255);
numberOfNames(42)
应该等于53174。
assert.equal(numberOfNames(42), 53174);
numberOfNames(123)
应该等于2552338241。
assert.equal(numberOfNames(123), 2552338241);
--seed--
--seed-contents--
function numberOfNames(num) {
return true;
}
--solutions--
function numberOfNames(num) {
const cache = [
[1]
];
for (let l = cache.length; l < num + 1; l++) {
let Aa;
let Mi;
const r = [0];
for (let x = 1; x < l + 1; x++) {
r.push(r[r.length - 1] + (Aa = cache[l - x < 0 ? cache.length - (l - x) : l - x])[(Mi = Math.min(x, l - x)) < 0 ? Aa.length - Mi : Mi]);
}
cache.push(r);
}
return cache[num][cache[num].length - 1];
}